I am running a remote shell script from a local shell script using ssh. Below is the code in my local shell script:
ssh userid@remote_server '/bin/bash' << EOF
if remote_shell_script.sh ; then
echo 'Script executed successfully'
echo 'Script failed'
The exit code of the EOF block will be passed back to the outer shell. The issue you may have is that the exit code of
remote_shell_script.sh is being swallowed. You can fix that a couple of ways. One is to
exit with an appropriate exit code.
ssh userid@remote_server '/bin/bash' << EOF if remote_shell_script.sh ; then echo 'Script executed successfully' exit 0 else echo 'Script failed' exit 1 fi EOF echo "Exit code = $?"
A simpler way is to move the checking logic to the local server. In that case you don't even need the EOF here document.
if ssh userid@remote_server remote_shell_script.sh; then echo 'Script executed successfully' else echo 'Script failed' fi