3

There is a very similar question to this, but there is an extra detail I have in my situation.

Basically I am using a ControlMaster to speed up SSH connections. So I am using:

CurrentUser=$(whoami)
session=$(ps -el | grep $(id -u) |sed -e 's/sshd//g'| grep ssh)
if [ "$session" = "" ]
then
        ssh -TMNf synchro@129.130.155.30 &
fi

After this code I have another command. The purpose of the ssh command is solely to run in the background in order to keep an open socket for faster connections (if no calls occur for a short time then it times out and closes due to inactivity.)

The problem is this script doesn't close and return to the caller. It becomes a < defunct > process, and doesn't return until I manually kill the created ssh session. How can I let the script return to the caller and have the created ssh run in the background?

Edit: I want the created ssh session to persist after the script ends to keep a socket open for faster connections with an rsync command after this. With an open socket I go from 3-4 second transfer times to milliseconds

3

you want to work with the nohup command?

  • nohup is interesting +1, and I might actually need it, but the problem isn't with the ssh session getting killed after the script terminates, it's with returning to the calling script from the script that creates the ssh session. (I tried it and no dice :() – Joshua Enfield Aug 17 '10 at 14:39
  • I got it using your link - nohup ssh -TMNf synchro@129.130.155.30 >/dev/null 2>&1 </dev/null & Thank you. I wasn't redirecting the output which fixed it. – Joshua Enfield Aug 17 '10 at 14:53
3

How about giving autossh a try:

http://www.harding.motd.ca/autossh/

It manages the SSH connection for you and returns to the caller once you kick it off.

  • I'd like to get my custom solution working if possible, if no other feasible answers exist I will look into implementing\learning autossh. – Joshua Enfield Aug 17 '10 at 14:42

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.