Magazine

Running Scripts Or Processes Even If the User Logs out

Posted on the 04 May 2021 by Satish Kumar @satish_kumar86

Sometimes, we may need ourscriptto run evenafterwe log out, such as when making a backup and similar activities. In this case, even if we log out, the system is powered on and running. In such situations, we can use thenohupcommand. Thenohupcommand prevents the process from terminating by using theSIGHUPsignal.

Thenohupcommand makes our script run without attaching it to a Terminal. Therefore, if we use theechocommand to print text on the Terminal it will not be printed in a Terminal, since the script is not attached to a Terminal. In such cases, we need to redirect the output to the file, ornohupwill automatically redirect the output to anohup.outfile.

Therefore, if we need to run a process, even if we log out, we need to use thenohupcommand as follows:

$ nohup command &

The example is as follows:

$ nohup sort emp.lst &

This will run a program to sort the emp.lst file in the background.

$ nohup date &

You Might Also Like :

Back to Featured Articles on Logo Paperblog

These articles might interest you :