Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Raspberry Pi connected to a digital temperature probe, which measures my fermenting beer. A python script reads the temperature every second and prints it to the console, and stores it in a MySQL database.

I enjoy and benefit from watching the temperature from the console on my computer over SSH during the day time. However, during the night, I hit Ctrlc and run the following:

nohup python thermometer.py

Which allows me to shut down my SSH and my computer while retaining the temperature gathering. At 7am I hit Ctrlc and then run the following:

phython thermometer.py

I do not wish to do this manually any more.

I would prefer some type of script that simply issued the nohup command at 12am and returned to the normal python command at 7am.

How can I do this in the most "linux appropriate" manner?

I am pretty new to Linux; for example, I learned of the nohup command on the RPi stackexchange...

I guess that either a modified python script issuing an os command or a batch script would be most appropriate.

share|improve this question
Have you thought about running the script in tmux or screen and attaching/detatching? (+1 for the first sentence of this question)... – jasonwryan Jul 12 '13 at 7:19
Honestly I am ignorant of tmux or screen, but thank you I will look them up! – Matthew Moisen Jul 12 '13 at 7:26
@jasonwryan Honestly I am ignorant of tmux or screen, but thank you I will look them up! – Matthew Moisen Jul 12 '13 at 7:47
up vote 2 down vote accepted

If you run the script with nohup python thermometer.py & it will write the output to nohup.out file.

So whenever you want to read the output use tail -f nohup.out. (You don't have to kill the process every time or automate to change the nohup)

share|improve this answer
The very similar alternative is to redirect the process output to a log file, eg nohup python thermometer.py > logfile 2>&1 &. You can then simply log in at any time and "follow" the log file. Basically you are turning the script into a basic "service". – Johan Jul 12 '13 at 8:48
Manula, the tail -f nohup.out command reveals the database warnings I always see when I run python thermometer1.py but it is not revealing the print commands for some reason? Interestingly, when I hit ctrl+c in the nohup window, the tail window then prints out the last 10 lines of temperatures and the python error message from the KeyboardInterrupt. Any speculations? In addition, if I ctrl+c and then issue tail -f nohup.out again I only see the database warnings but not the print output. I am printing to the console via python's print command. – Matthew Moisen Jul 12 '13 at 17:41
@Johan by following the logfile do you mean issuing tail -f logfile? If so, I am getting the same problem as with the comment above. – Matthew Moisen Jul 12 '13 at 17:43
@MatthewMoisen You can use nohup python print.py 2> /dev/null 1> out.log & tail the out.log file – Manula Waidyanatha Jul 12 '13 at 18:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.