Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
You're missing the link to "this". –  Dennis Williamson Aug 17 '10 at 14:39

2 Answers 2

up vote 3 down vote accepted

you want to work with the nohup command?

share|improve this answer
    
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

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.

share|improve this answer
    
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

 
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.