Use nohup for scripts that should continue when you log out of server

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.

Last Updated: 2024-11-23

I wanted to download a website locally to analyze a competitor. I realized I would cripple my local office internet connection for a few hours if I did it at home, so I decided to do on it from one of my servers. So I SSH-ed in and ran my script:

$ wget --wait 1 --random-wait -k -p -m -E -r example.com

This started well, but when I logged out of my SSH, it stopped, since the process was a child of SSH process and this process got killed when my connection was closed.

The solution was to wrap in nohup and background the task (&) such that I could still do things in the terminal:

$ nohup wget --wait 1 --random-wait -k -p -m -E -r example.com &

Note that nohup logs to nohup.log in the same directory. This is usually a good thing, but may prove problematic if the logs are huge (in this case redirect to /dev/null)