From: Rob Biedenharn Date: 2008-12-18T23:54:30+09:00 Subject: Re: Net::SSH - kick off background job On Dec 18, 2008, at 9:26 AM, Douglas Seifert wrote: > On Thu, Dec 18, 2008 at 2:27 AM, Brian Candler > wrote: >> Sebastian W. wrote: >>> Does anyone know of a way to tell Net::SSH to start running a >>> script but >>> then effectively "disown" that process? >>> >>> I have a long-running job I'd like to kick off using Net::SSH but I >>> don't want the connection to persist for the entire length of the >>> job. I >>> just want to kick off the job, let it start running and then >>> basically >>> not care what happens. Of course I care, but I have a different >>> process >>> that will actually pick up whether or not the long-running task was >>> successful or not. >> >> nohup somecommand someargs & >> > You probably need something like this: > nohup somecommand someargs > /tmp/out.log < /dev/null & > > the "< /dev/null" lets you detach the job from the terminal. > > Cheers, > Doug Seifert If your platform has setsid (set session id), that is a better option for something like this. setsid somecommand someargs > /tmp/out.log 2>&1 Note the use of 2>&1 to redirect stderr(2) to(>) the same(&) place as stdout(1). The order is important, redirect stdout first. Also note that you do not put this command in the background with & like in the nohup case. A new process is forked by setsid so that the session id can be set and the controlling terminal disassociated from the process. -Rob P.S. Of course, this isn't Net::SSH specific, but applies to any Linux system. Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com