Alternatives to nohup?

Solution 1:

Ok, so there are several options:

  • disown

You can combine disown and & to push your script to the background

$ disown [your_script] &
[your_script] can be checked by the jobs command. Once typed you will see:

$ jobs
[1]+ Running [your_script]

And the killing can be done by kill %1, the 1 refers to the job number seen above. This is the better alternative to nohup as it does not leave the nohup.out files littered all over the file system.

  • screen

Is a "virtual" terminal which you can run from a "real" terminal (actually all terminals today are "virtual" but that is another topic for another day). Screen will keep running even if your ssh session gets disconnected. Any process which you start in a screen session will keep running with that screen session. When you reconnect to the server you can reconnect to the screen session and everything will be as if nothing happened, other than the time which passed.

Excellent source: Speaking UNIX: Stayin' alive with Screen".

Solution 2:

I cannot perfectly understand your problem but...

In my case, I use screen for such long running background jobs. It provide virtual terminal, which is attachable/dettachable anytime. So I can logout from original session without closing the virtual session, and get that session back anytime I want.

anyway, this is not for init.d style scripts.

Solution 3:

Use & after your command in script like :

your command here > /dev/null 2>&1 &
exit