2

I'm running a number of scripts which often include an exit clause if the preceding commands fail, e.g.:

[ ! -d $somefile ] && exit 1;

However, I'm running this through an ssh session, and if one of these exits are executed I'm kicked out of the ssh session. Is there a way to run a script but capture any exit commands to avoid it closing the ssh connection? Changing all the scripts is not an ideal option.

7
  • 5
    Unless you source those scripts, this should not be happening. ... Unless your interactive shell is running with set -e? Commented Sep 29, 2015 at 11:48
  • @tripleee The script is probably being run in place of the default command (ssh you@host some_script.sh). Commented Sep 29, 2015 at 11:49
  • 1
    @chepner But then what would "avoid closing the ssh connection" mean here? ssh you@host 'some_script.sh || bash -i'? Commented Sep 29, 2015 at 11:50
  • That's what I was imagining. Run the script, but drop into a remote shell for debugging/triage if the script fails. Commented Sep 29, 2015 at 11:51
  • @jodles Presumably, the script exits for a reason. Simply continuing the script wouldn't be a realistic option, so I suspect tripleee's suggestion is close to what you want. Commented Sep 29, 2015 at 11:57

1 Answer 1

-1

You use ssh session. If you just write

exit 1

then your current ssh session will be finish.

To avoid finish use -c

bash -c "exit 1"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.