Temperature by email


Is there a way to automatically monitor the temperature and make DietPi send an email when the rPi’s temperature exceeds a certain threshold?


currently there is no Email notification function on DietPi.

There are a couple of tutorials on the web describing how to setup an email function as well as a temp monitoring script.

Thank you. :slight_smile: I thought there would be a DietPi method, but true, there are many scripts and ideas throughout the internet. I was unsure how to run a script like every few minutes, but I totally overlooked there is cronjobs for that haha … should be feasible then :slight_smile:

Yes you could use DietPi cron function to schedule your job

I installed lm-sensors on my system…actually on all my linux systems…it’s nice to be able to see the temps of different temperature sensors on a machine, but not sure how it can email if temps get out of specs.


I did find this though

Okay, I got it to work to send an email. :slight_smile: The email arrives and tells the CPU temperature.

However, the cronjob doesn’t seem to work. It’s strange. Manually calling the monitoring script from the command line works like a charm and the email gets delivered within seconds, but calling the script by cronjob doesn’t seem to cause anything, even after a reboot of rPi. Mmh …

Here’s the cronjob line, the script should be run every two seconds:

*/2 * * * * bash /usr/local/bin/temp_mon

Is there something wrong with it?

I wrote a little bash script and use package “dma” (including sendmail) to send emails.

neat…post it up!

Cron only allows for a minimum of one minute. What you could do is write a shell script with an infinite loop that runs your task, and then sleeps for 2 seconds. That way your task would be run more or less every 2 seconds, depending on how long the task itself takes.


while true; do
  # Do something
  sleep 2;

Sorry, this was a typo. I meant minute instead of second. Later I want to run the script only like every 10 Minutes or so.

But apart from that, the current cronjob command doesn’t seem to run at all, no matter if I set it to 1 minute or 2 minutes or whatever. I can execute the script manually, but cronjob fails. No clue why.

hmm can you try the following

0,5,10,15,20,25,30,35,40,45,50,55 * * * * <your script>

maybe */x notation is not understood correctly

If it still seems to be not working after that, change the command to something like:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * date >>/tmp/debug_cron_pax.txt

The */2 notation is interpreted correctly. We use that for implemented minutely timer as well (dietpi-cron > minutely). Have you verified sufficient permissions of the crontab’s user to execute the script?

One can also increase cron log level via /etc/default/cron.

That was a good hint and, indeed, it works. It’s not the notation, */5 … works, too: the txt file is being created and a new line added every five minutes. So the problems seems to be related to my script somehow. :thinking: What would make a script not being run by cronjob?

I’ll try that and see what I find …

Ahh, I’m getting closer. The error is not caused by cron but by the mailing program, it trys to send to the wrong email address. But not sure why. When executing the script manually it works, when exectuted by cron the mailer uses different mail settings and hence fails.

Heureka … more or less :wink: I have to add “sudo” to the cronjob line to make it work:

*/2 * * * * sudo bash /usr/local/bin/temp_mon

I only don’t understand the reason why it doesn’t work without that “sudo”.

probably it has something to do with the user environment the cron is executed with.

Good idea. Done so here. I’m a Linux novice tho.