15

I have a bash script that takes several hours to run. While it's running, I would like to do other things, which may involve logging out or disconnecting from the internet (my script runs network tests on various computers).

I understand that there is a command that would allow me to run my tests from a remote terminal and logout of the terminal while it runs. Does anyone know what this command is?

3 Answers3

18

The command you are looking for is nohup.

There is also screen, which is for when you want to leave something running but come back and reattach interactively later.

nohup is simpler if a command expects no user input after launch, and screen is better if you want to be able to run the program interactively.

Justin Smith
  • 4,166
1

I use nohup for this. In my case I had a python script named action.py I ran the script on a remote server with nohup python action.py & I would then close the terminal. Later when it's finished running, you can see all output from the process in nohup.out which will be created in the same directory as action.py. If the file already exists further output will be appended to it.

The only snag is not knowing when the script has run its course, so in my case I had it shoot me an email upon completion. Hope this helped someone!

Bryan J
  • 11
0

What happens if you forgot to add the nohup Command at the beginning of your Command?

Let us say that you have run the following Long Command:

The beginning of the Output of a Long Command

This is called as ls -Ral / that is supposed to list all of the Files and all of the Folders, including the Hidden ones, with a Long Format, Recursively starting from the Root Folder. It might take a while.

Just press ctrl+Z.

Stopping the Long Command

How do you get it back?

The Command to get it back into the Foreground is fg.

Bringing the Command back