Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see the output console after running a nohup command?

I have a code running on a Linux server. Since it takes hours to run, I have to use nohup to make sure my code is still running in case I loose my connection to the server. Again since I have to wait hours to see the results, I defined a counter to print out the progress of my code (%). If I loose my connection to the server or close the terminal, the only way that I can see the code is still running is using top. Is there any way that I can see again the output console (message showing the progress)?

like image 579
MTT Avatar asked Feb 05 '15 17:02

MTT


People also ask

Where can I see nohup output?

nohup. out file will be in location of your present working directory ,pwd. (the directory from where you executed command).

How do I know if nohup is completed?

If you see the name of your process/program among those listed then it hasn't finished yet. To check the results or status of the programs, log back in to the same server. Once the job has finished its output will be contained in a file located within your home space. The filename will be "nohup.

What is nohup output?

nohup is a POSIX command which means "no hang up". Its purpose is to execute a command such that it ignores the HUP (hangup) signal and therefore does not stop when the user logs out. nohup.

How do I save nohup output?

If you want to redirect the output of nohup command to file, just add it at the end of command after > redirection operator. Here is an example. In this case, the output of shell script will be sent to /home/ubuntu/data. txt file.


2 Answers

You can see the output in real time by running below from another terminal.

tail -f nohup.out 
like image 99
yfpb Avatar answered Oct 07 '22 06:10

yfpb


You can redirect standard output and standard error to a file and look at that file. eg:

nohup command 2>&1 > outputfile & 

note default behavior from man page:

If standard output is a terminal, append output to 'nohup.out' if possible, '$HOME/nohup.out' otherwise. If standard error is a terminal, redirect it to standard output

so really you can just run

nohup command & 

and then look in nohup.out

like image 20
Mike Atkins Avatar answered Oct 07 '22 06:10

Mike Atkins