I have a bunch of bash commands that are run via ssh:
#!/bin/bash
CMD="
set -e
cmd1
cmd2
# ........
service my_service stop
# .........
# some commands here......
# .........
service my_service start
"
ssh -t -A -q -C $SERVER@$HOST "$CMD"
Sometimes, whenever my_service
happens to be in the stopped status already, the command service my_service stop
will return this:
--rpc-eval : RPC failed with reason :nodedown # it's an Erlang app, hence a response
./my_script.sh: línea 26: error: orden no encontrada
Since the said command is deemed failure, for some reason, it'll terminate the execution, exit a session and thus won't reach the command service my_service start
.
But I want it to always run both stop
and start
and the commands in between, of course, regardless of the state of an app before the command service stop
, and not to fail, or move on despite a possible failure after "service stop"
How to do it?