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 [email protected] & 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

1
  • You're missing the link to "this". Commented Aug 17, 2010 at 14:39

2 Answers 2

3

you want to work with the nohup command?

2
  • 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 :() Commented Aug 17, 2010 at 14:39
  • I got it using your link - nohup ssh -TMNf [email protected] >/dev/null 2>&1 </dev/null & Thank you. I wasn't redirecting the output which fixed it. Commented Aug 17, 2010 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.

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.