DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2011-01-19 17:28:40

neerav
Member
Registered: 2011-01-16
Posts: 15

Keep a command running after ssh session quits

I want to run my initial rsync backup command through ssh.  The first backup on my DNS-321 from RHD to LHD will take a few days (tested at approx 4MB/sec).  I cannot run this backup as the planned daily cronjob, since it will take so long.  Thus, I am going to run the initial rsync manually.

However, if I close/lose the terminal connection for some reason, the rsync will stop.  Putting an "&" at the end of the command only puts it into the background -- the process will still quit when the terminal session closes.  What is the command/procedure to keep the process running to completion even after the initiating terminal closes?


Neerav
DNS-321 • 2 x 2TB WD20EADS in standard mode • ffp 0.5

Offline

 

#2 2011-01-19 17:36:07

fonz
Member / Developer
From: Berlin
Registered: 2007-02-06
Posts: 1716
Website

Re: Keep a command running after ssh session quits

Learn about screen and/or nohup. That's a standard Linux question.

Offline

 

#3 2011-01-19 17:40:01

neerav
Member
Registered: 2011-01-16
Posts: 15

Re: Keep a command running after ssh session quits

Thank you, Fonz, for a point in the right direction.


Neerav
DNS-321 • 2 x 2TB WD20EADS in standard mode • ffp 0.5

Offline

 

#4 2011-01-19 19:07:09

bgravato
Member
Registered: 2010-11-04
Posts: 44

Re: Keep a command running after ssh session quits

Check also dtach, simpler than screen.

Offline

 

#5 2011-01-19 21:08:35

rsd76
Member
Registered: 2010-04-18
Posts: 47

Re: Keep a command running after ssh session quits

I always use:
echo "/path/to/program_or_script > /path/to/logfile 2>&1" | at now

The program than runs like it is started from cron (it is essentially).

I have had programs not running OK with nohup on unix OSses.


Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us. (Calvin & Hobbes)

Offline

 

#6 2011-01-20 05:27:12

neerav
Member
Registered: 2011-01-16
Posts: 15

Re: Keep a command running after ssh session quits

Thanks bgravato and rsd76 for the additional commands.

After doing the research into these commands:
1) screen is beyond me at this point.  I see the long-term benefit of learning it so it's on my to-do list.
2) dtach looks promising, though I'm not sure it's feasible on the DNS-321, I'm going to be installing and playing with it on my Mac.
3) I've currently decided on, and implemented a mix between the echo and nohup suggestions. 

I put the complicated rsync command, with redirecting the output into a logfile, into its own shell script.  Make it executable.  An important modification is to add the "--progress" and "--stats" options to rsync.  These options give the status of the file as it's sync'ed as well as transfer speed, estimate of remaining time (for the current file), number of files remaining to sync, and total number of files checked.

Then I run the script:  nohup /path/to/script &    The command prompt returns and I'm free to do other things or close the shell.

Whenever I want to check up on the progress: tail -f /path/to/logfile

In case the script needs to be killed for some reason: kill -2 PID.of.script  (a higher level signal [-2] is needed since we explicitly am ignoring the sighup [-1] signal).  May need to "kill PID.of.children" if they don't automatically go away.

This may not be the most efficient method, but it is the easiest to implement.  I figure that inefficiency couldn't add too much to an already 5+ day initial rsync run, or at least nothing I'm going to notice. wink

Last edited by neerav (2011-01-20 05:28:51)


Neerav
DNS-321 • 2 x 2TB WD20EADS in standard mode • ffp 0.5

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB