I need to get indication whatever the ssh
command succeeded or not without it leaving the connected server.
I use this command:
ssh -q user1@server1 "echo 2>&1" && echo SSH_OK || echo SSH_NOK
My problem with that command is that I don't stay in the connected server. I don't wish to add test after the ssh
command, I wish to do it like how I do it so far - by one command.
Here is a sample of how it works now:
[nir@dhcppc4 ~]$ ssh -q user1@server1 "echo 2>&1" && echo SSH_OK || echo SSH_NOK
SSH_NOK
[nir@dhcppc4 ~]$ hostname
dhcppc4
[nir@dhcppc4 ~]$ ssh -q user1@server2 "echo 2>&1" && echo SSH_OK || echo SSH_NOK
SSH_OK
[nir@dhcppc4 ~]$ hostname
dhcppc4
And here is a sample of what I want:
[nir@dhcppc4 ~]$ ssh -q user1@server1 "echo 2>&1" && echo SSH_OK || echo SSH_NOK
SSH_NOK
[nir@dhcppc4 ~]$ hostname
dhcppc4
[nir@dhcppc4 ~]$ ssh -q user1@server2 "echo 2>&1" && echo SSH_OK || echo SSH_NOK
SSH_OK
[nir@server2 ~]$ hostname
server2
SSH_NOK
- can I avoid this? – Nir Oct 04 '13 at 14:22SSH_NOK
is output when the ssh client exits with non-zero exit code (either you kill it or the last command before logging out exits with an error) – peterph Oct 04 '13 at 15:21ctrl+d
, withexit
it is what I want. No need to elaborate, your answer is good enough. – Nir Oct 04 '13 at 15:45