Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Python script and emhttp notify via cron

Featured Replies

I wrote a simple python script which checks the CPU temp and uses /usr/local/emhttp/webGui/scripts/notify to alert. From the command line it seems to run fine just not from the crontab. This is what I see.

 

Jun  4 12:06:01 clarabell crond[1731]: exit status 1 from user root /root/scripts/check_cpu_temp.py
Jun  4 12:06:01 clarabell sSMTP[27055]: Creating SSL connection to host
Jun  4 12:06:02 clarabell sSMTP[27055]: SSL connection using ECDHE-RSA-AES128-GCM-SHA256
Jun  4 12:06:05 clarabell sSMTP[27055]: Sent mail for [email protected] (221 2.0.0 closing connection h39-v6sm14129640edb.65 - gsmtp) uid=0 username=root outbytes=598

 

It appears /usr/local/emhttp/webGui/scripts/notify doesn't seem to run with the settings as configured through the GUI ([email protected] ??? is not the email configured), presumably due to the way it gets invoke through the cron, maybe run in

 

Thoughts?

 

Script:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import subprocess
import re

MAX_THRESHOLD = 30

process = subprocess.Popen(['/usr/bin/sensors'], stdout=subprocess.PIPE)
out, err = process.communicate()

for line in out.split("\n"):
    if line and not line.isspace():
        m = re.match(r'CPU Temp\:\s+[+]?(\d+(\.\d+)*)\s?°([CcFf])',line)
        if m:
            try:
                temp = float(m.group(1))
            except ValueError:
                print "Not a float"
            break

if temp > MAX_THRESHOLD:
    command_line = ['/usr/local/emhttp/webGui/scripts/notify', '-i', 'alert', '-s', 'unRAID CPU Temperature High', '-d', 'Temperature at %s degrees' % temp]
    process = subprocess.Popen(command_line, stdout=subprocess.PIPE, shell=False)

 

 

 

IIRC any exit status from a script other than zero will trigger an email via cron to "root"

  • Author
11 minutes ago, Squid said:

IIRC any exit status from a script other than zero will trigger an email via cron to "root"

 

It's odd that the script triggers an exit status other than zero via cron but one thing for sure, the /usr/local/emhttp/webGui/scripts/notify command is not running properly through python via cron.

 

If I run from the command line I see the valid outgoing email account as configured through the GUI Notifications email setup, but through cron I see: [email protected]

 

Sent mail for [email protected] 

Closer look at the error though shows it trying to run via cron from /root/scripts. Did you mean /boot/scripts?

  • Author
4 minutes ago, Squid said:

Closer look at the error though shows it trying to run via cron from /root/scripts. Did you mean /boot/scripts?

 

Thanks for the help Squid but the path is fine, I copy my scripts to /root on boot up via the go file.

 

file /root/scripts/check_cpu_temp.py
/root/scripts/check_cpu_temp.py: Python script, UTF-8 Unicode text executable

I think it has more to do with the way python invokes the shell to run the the notify command (script) or something. Maybe I'll try to simply rewrite the script as a bash script instead.

Archived

This topic is now archived and is closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.