Results 1 to 3 of 3
Hello
I'm running a command using ssh:
for ex:
ssh xyz-server "for i in 1 2; do ls -ltr /a/b/c/d; echo; done" | tail
Pls NOTE:
- when im doing ...
- 06-12-2009 #1
ssh command with pipe - how to get return code
Hello
I'm running a command using ssh:
for ex:
ssh xyz-server "for i in 1 2; do ls -ltr /a/b/c/d; echo; done" | tail
Pls NOTE:
- when im doing "ssh xyz-server" then ssh session is taking me to this server
without giving password.
Question:
If i change the server name to any invalid server name i.e. xyz-server111 or xyz-server222 then i'm getting the below error mesg:
ssh: xyz-server111: Temporary failure in name resolution
and i was trying to get the return code of the ssh command i.e. if the server is not valid (ssh will give this error / will not work/ perform any ls -ltr..) then it will return a non-zero value. But as I'm using "|" at the end of ssh command i'm not able to know whether ssh command actually ran good or not. With "| tail" at the end of ssh command and wrong server name (with above error mesg), i'm getting return code($?)= 0.
Any help!
brgds
/Arun Sangal
720 251 9962
- 06-13-2009 #2Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
Check bash variable PIPESTATUS. It is an array containg the return status of each command in the string of commands that were piped. The ssh command is the 1st command so check element 0.
Code:echo ${PIPESTATUS[0]}
- 06-16-2009 #3Just Joined!
- Join Date
- Sep 2006
- Posts
- 2
use something like this
ssh -T mylinux.com -l username -c "commands to execute with semicolon separated" `<dev/null >/dev/null 2>&1`


Reply With Quote