Welcome

Troves being gleaned while surfing on the Internet mostly about computer/IT/system skills and tricks, Welcome here ...
Powered By Blogger

Disclaimer

This blog is written by the owner with real practices and tests and intended to hold all original posts except there is a clear declaration for referencing from others. Thanks for tagging with the source link or other tips for reference from here if you would like to quote partial or full text from posts in this blog.

Friday, December 31, 2010

uninterruptedly running program in the background but need enter password or something ?



For instance, wanna copy a big file, more than 10G, say, from remote host to local machine by a shell like :

 scp -r user@hostname/ip:/home/data/bigdata   /home/user/ 

but fearful of the interruption if the session will be terminated, so use nohup to achieve an interrupted execution to guard against being drawn to end due to the termination somehow of the current login session. by

nohup scp -r user@hostname/ip:/home/data/bigdata   /home/user/  

But most of the time you also want to lay this task go in the background since it should take a multitude of time to remote-copy a file as big as 10G, so change into

nohup scp -r user@hostname/ip:/home/data/bigdata   /home/user/ &

By this point it comes what I want to share: you are guaranteed to run across an OOPS:

nohup: ignoring input and appending output to `nohup.out'

[1]+  Exit 1                  nohup scp -r user@hostname/ip:/home/data/bigdata /home/user/


this is just because the process is suspended to receive a user input for password.

So there seemingly exists an ambivalent occasion here.  By session controlling command, we can circumvent around this plausible dilemma:

nohup scp -r user@hostname/ip:/home/data/bigdata   /home/user/  
enter the password
CTRL+Z ( force the foreground process back to the background to run like a daemon )
 [1] 3581

bg $jobid (you can see the jobid appearing after CTRL+Z, here it is 1)


Later if wanna change it back to run in the foreground,  do it by


fg $jobid.

* you can also change the default output of nohup and include all the copying log into a self-defined log file by

nohup scp -r user@hostname/ip:/home/data/bigdata   /home/user/   1> bigdata.scp.log 2>&1

1 comment:

leon said...

Thanks is great. THanks for your tips and explanations!