ssh uses here-document problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh uses here-document problem
# 1  
Old 07-05-2012
ssh uses here-document problem

I try to ssh uses bash script in here-document like this.

Code:
ssh root@$SERVER <<EOF
if [ `service httpd status | grep stop` ]; then
    service httpd start
fi
exit
EOF

But got an error below.

Quote:
Pseudo-terminal will not be allocated because stdin is not a terminal.
-bash: line 1: [: is: binary operator expected
TERM environment variable not set
maybe the if command causes the problem. Thanks for help.
# 2  
Old 07-05-2012
That's not correct if-syntax outside a here-document, let alone inside one.

The backticks get substituted before the here-document even gets sent to the remote side, too -- but you don't even need them. You don't even need a here-document...

Code:
ssh username@host "service httpd status | grep stop >/dev/null && service httpd start"

# 3  
Old 07-05-2012
It's really helpful. I need to get used to this. Thanks a lot.

Last edited by muffle; 07-10-2012 at 01:34 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with here-document not seeing delimiter

System is Oracle Linux 6 (derivative of RHEL) Given this script (copied from vi with line numbering for reference) 1 #!/bin/sh 2 ORAENV_ASK=NO 3 echo "*****************************************************" 4 echo "** Stop all databases and listener" 5 echo... (6 Replies)
Discussion started by: edstevens
6 Replies

2. Solaris

Problem with SSH

Hi guys. I am using VirtualBox to run Solaris on my host (Windows 7) . I have setup networking and am able to ping from Solaris to Windows 7 and vice versa. Now I want to be able to SSH from Windows 7 to my guest (Solaris) On solaris , the output to ps -ef | grep ssh shows: ... (8 Replies)
Discussion started by: Junaid Subhani
8 Replies

3. Programming

Foreground sesu SSH with here document

I'm trying to write a foreground (password prompt) ssh command, passing in a here doc - any idea where I'm going wrong? ssh <user>@<targetserver> /usr/seos/bin/sesu - <targuser> -c /usr/bin/ksh "param1" << EOF date echo ${1} EOF Tells me "Invalid option param1". However a simple date... (8 Replies)
Discussion started by: doonan_79
8 Replies

4. Programming

Background SSH using here document

I'm trying to use Here documents to pass several commands to a remote server over SSH. However I'm having problems. The code is as follows: nohup ssh $i_hostname exec /usr/bin/ksh -s << EOF >> $AS_STOPSAP_LOG & echo $i_instname; ps -ef | grep name | grep ${i_instname} |grep -v grep ... (4 Replies)
Discussion started by: doonan_79
4 Replies

5. Shell Programming and Scripting

Here document inside a here document?

Can we use a here document inside a here document? Something like this ssh user@remotehost << REMOTE sudo vserver vsernamename enter << VSERVER perform actions on vserver. VSERVER REMOTE (6 Replies)
Discussion started by: mnanavati
6 Replies

6. UNIX for Dummies Questions & Answers

Problem with Sudo inside a here document

Have a sudo statement inside of a here document. It prompts me for a password, but doesnt wait for me to enter my password. Is there a way I can use the command without sudo or anyway that I can enter the password correctly? Eg : while read remotehost do ssh -t $2@$remotehost ... (0 Replies)
Discussion started by: mnanavati
0 Replies

7. Shell Programming and Scripting

ssh and here document

Hi :) how can I use here doc to use ssh? I am facing a problem with the below script: #!/bin/bash ssh hosein@localhost << * 123456 * "123456" is my password Thanks (2 Replies)
Discussion started by: htabesh
2 Replies

8. Shell Programming and Scripting

ssh script problem problem

Hi Please help me with the following problem with my script. The following block of code is not repeating in the while loop and exiting after searching for first message. input_file ========== host001-01 host001-02 2008-07-23 13:02:04,651 ConnectionFactory - Setting session state... (2 Replies)
Discussion started by: pcjandyala
2 Replies

9. UNIX for Advanced & Expert Users

Problem with ssh

Hi All, I get the following error message when i try to ssh to a node ssh_exchange_identification: Connection closed by remote host this is the output when i run in verbose mode Sun_SSH_1.1, SSH protocols 1.5/2.0, OpenSSL 0x0090704f debug1: Reading configuration data... (1 Reply)
Discussion started by: raman1605
1 Replies

10. UNIX for Advanced & Expert Users

SSH Problem auth problem

Hi, Just recently we seem to be getting the following error message relating to SSH when we run the UNIX script in background mode: warning: You have no controlling tty. Cannot read confirmation.^M warning: Authentication failed.^M Disconnected; key exchange or algorithm negotiation... (1 Reply)
Discussion started by: budrito
1 Replies
Login or Register to Ask a Question