Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

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

EDIT:

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

share|improve this question
    
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.

share|improve this answer
    
thanks, please see the EDIT – Oleg Shirokikh Jul 10 '15 at 23:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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