SSH – Managing Job Control Effectively

job-controllinuxnohupssh

I can't seem to figure out a decent way to manage jobs over ssh. I want to start a job in an ssh session, logout, log back in, do a fg, check on the job, logout, then repeat the whole process. nohup doesn't seem to wrok well.

I used this command

 $ nohup script & > nohup.out 
 [1] 28128
 $ nohup: ignoring input and appending output to `nohup.out'
 [1]+  Exit 255                nohup script

If I do either

$ jobs
$ ps -ef |  grep script

I get nothing, i.e. the process isn't found.

Also, a related question I have is: If I'm in an ssh session, and want to send a job to the background, ctrl-z doesn't work. What to do?

Cany anyone help me out?

Best Answer

well - one of the options is to use screen.

  1. you log on
  2. you fire up screen
  3. you run your job
  4. you press ctrl+a d to detach
  5. you log off
  6. after few hours you log on arain and run screen -r - you have your shell / job result in front of you. or maybe it still runs...

more examples here.

another - probably worse if it's one time job - option is to demonize your shell script, add proper logging and use start-stop-daemon to run it in the background until it finishes. status - can be checked in logs produced.