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.

  • 4
    Have you thought about running the script in tmux or screen and attaching/detatching? (+1 for the first sentence of this question)...
    – jasonwryan
    Commented Jul 12, 2013 at 7:19
  • Honestly I am ignorant of tmux or screen, but thank you I will look them up! Commented Jul 12, 2013 at 7:26
  • @jasonwryan Honestly I am ignorant of tmux or screen, but thank you I will look them up! Commented Jul 12, 2013 at 7:47

1 Answer 1


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)

  • 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
    Commented Jul 12, 2013 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. Commented Jul 12, 2013 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. Commented Jul 12, 2013 at 17:43
  • @MatthewMoisen You can use nohup python print.py 2> /dev/null 1> out.log & tail the out.log file Commented Jul 12, 2013 at 18:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .