I have a shell script that runs on my server every day. It does some house cleaning and connects to a remote host to perform other tasks i.e.
#!/bin/bash
#do something...
...locally...
#run remote script...
ssh user@remotehost "/opt/process/verify.sh"
exit
It works fine but to be safe I would like to capture (if possible) the return code from "/opt/process/verify.sh" i.e.
I started reading about the command trap
. Can I use it for that purpose? Is there another option?
ssh
returns the return value of the command in question, or 255 if an error occurred in ssh
itself. Simply check this value and take appropriate action.
You can use the $? variable to get the response code. For instance:
% ssh somebox /bin/true
% echo $?
0
% ssh somebox /bin/false
% echo $?
1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With