2

I am facing a problem regarding SSH, which exits when I don't want it to. My goal is to run multiple script (which are tests) and evaluate their exit value to detect errors on my project.

First, I will describe the process :

  • I have a local machine on which I run a script which call the following command :

    ssh -t -o StrictHostKeyChecking=no -o ServerAliveInterval=30 -i $PRIVATE_KEY $REMOTE_USER@$REMOTE_IP  "cd ~/path/to/scripts && "$CMD
    

    CMD is the script to run on the remote machine

  • On the remote machine, the "primary" script calls multiple "secondary" bash and python scripts.

And here is my problem : when one of the "secondary" python script called on the remote by the "primary" script exits with a value different from 0, it terminates the ssh connection without coming back to the "primary" script.

What can I do to prevent my SSH connection to terminates on an error of a "secondary" script ? I need my primary script to run until the end.

2
  • Well, I'm sorry for the pollution of the site, but I just realised that my command $CMD was executing my script with the '-e' option ... Sorry for the inconvenience
    – Legh
    Nov 29, 2023 at 10:32
  • No, this is interesting, please answer your question with your findings - that will help others! If your answer is good, I'll even upvote it.
    – thecarpy
    Nov 29, 2023 at 10:40

1 Answer 1

2

As mentioned in my comment, the command passed to the SSH is bash -e path/to/script, which terminates the script on any non zero exit status.

This choice of option was necessary to catch a Ctrl+C command from the user and stop the tests. This seems incompatible with my problem (not terminate the SSH connection on error and at the same time terminates it on Ctrl+C command).

I think my topic is solved.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .