I want to write a small script to automate some commands in python for unix and linux, thru pexpect.
Ex:
ssh -t [email protected] "uname -r && some_cmd_that_exist_or_not && exec /bin/sh"
The problem, is that I don't know from the beginning what type of the OS the machine has, and in some cases the commands are not available.
In this case the connection is closed and a "command not found is returned". I want to continue executing even if a command is not found.
After that I retrive the output using pyexpect. My issue is that I couldn't find an option to keep the connection open if a commad is not found.
Just replace the &&
with ;
:
ssh -t [email protected] 'uname -r; some_cmd_that_may_not_exist; exec /bin/sh'
The &&
is a short-circuiting operator, so it will stop executing commands as soon as any of the commands fail. If you want to run them all, just don't use it.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments