joelones Posted June 4, 2018 Share Posted June 4, 2018 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) Quote Link to comment
Squid Posted June 4, 2018 Share Posted June 4, 2018 IIRC any exit status from a script other than zero will trigger an email via cron to "root" Quote Link to comment
joelones Posted June 4, 2018 Author Share Posted June 4, 2018 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] Quote Link to comment
Squid Posted June 4, 2018 Share Posted June 4, 2018 Closer look at the error though shows it trying to run via cron from /root/scripts. Did you mean /boot/scripts? Quote Link to comment
joelones Posted June 4, 2018 Author Share Posted June 4, 2018 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. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.