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)?
Advertisement
Answer
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