Suppose that bash script X is being called within another bash script Y. If I directly execute script X on a local machine, after X's completion, the program exits to the terminal.

However, when I execute script Y remotely via SSH, the (remote) terminal "hangs" after X's completion and doesn't exit even if X contains an exit command at the end.

How to make script Y to exit after completion of enclosed script calls, or move on to the next command when executed via SSH?

ssh -i $ssh_key $user@$host source $dir/scriptX.sh
//scriptX completes fine on SSHed machine, but remote machine hangs here


Another detail, which may be helpful. Deeper inside there is this script being called, which contains exec command.

  • Can you post the snippet of script Y that makes the SSH call and the call to script X? – John Jul 8 '15 at 17:43
  • @John - added + edited the question to make it clearer – Oleg Shirokikh Jul 8 '15 at 18:45

It probably means your script runs something in the background (with a &) that keeps tge terminal open. When your script ends, that something keeps running. ssh detects that, and doesn't close the session until the something quits.

In order to help you get the script to do what you want, you need to post the script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.