Saturday, April 23, 2022

[SOLVED] Do nohup or disown work on batch scripts?

Issue

I have a file containing 302 commands that start process on our server. Staring them all at once would kill it, so I have a script that pushes one command to the shell, waits for the process to finish and then calls the next.

This whole process will probably take a day or so to complete, and I'd like to log off in between. I know there's nohup or, if you forget that at the beginning, disown to make sure a process will still run even if you close the connection, but I'm not sure where I should put that call in my case. Only the script that channels the commands; only on the commands; or on both?

I apologize if this is a silly question, but I couldn't find a simple answer to exactly that question online and I can't risk disrupting these processes just because I got something wrong.


Solution

Sure you can use nohup:

nohup <script name> &

You can execute this command and the safely logout. You can then log back in and use ps command to see if your script is still running. I would also create a log file to be able to monitor the progress and redirect all standard and error output to that file.



Answered By - shargors
Answer Checked By - Mildred Charles (WPSolving Admin)