Webmin Cron Job issues

Discussion and Technical Support for general software applications and utilities including OS related issues.
Post Reply
Oscifer
Member
Member
Posts: 6
Joined: July 26th, 2013, 10:50 pm

Webmin Cron Job issues

Post by Oscifer »

First off thank you for the awesome guide!!

So I got the CPUTempshutdown script working after some tweaks. it works great as long as I run it from the terminal or putty, emails sent out correctly and system shutdown if necessary. However, as soon as I add it as a cron job to webmin it stops working. I get an email every time it automatically runs saying "/home/username/MyScripts/CPUTempShutdown.sh: 46: /home/username/MyScripts/CPUTempShutdown.sh: Bad substitution" No matter how I set the the two temps it won't send the proper email or shutdown the system. Any help would be greatly appreciated.
User avatar
Ian
Moderator
Posts: 752
Joined: January 1st, 2011, 7:00 am

Re: Webmin Cron Job issues

Post by Ian »

Hi there,

Can you show me the exact command you're running in cron please? You can do this by typing the following command in a Terminal and sending me the output:

Code: Select all

crontab -l
Thanks,

Ian.
Oscifer
Member
Member
Posts: 6
Joined: July 26th, 2013, 10:50 pm

Re: Webmin Cron Job issues

Post by Oscifer »

Output is:

* * * * * /home/user/MyScripts/CPUTempShutdown.sh 20 50

Doesn't matter how I set the temps when running it through webmin, I get the same error email.
User avatar
Ian
Moderator
Posts: 752
Joined: January 1st, 2011, 7:00 am

Re: Webmin Cron Job issues

Post by Ian »

Hmm :?

OK, can you paste your full script then please. Don't forget to blank out your email address.

Also, can you run it on command line using high temps eg. 50 80 and send me the output please.

Thanks,

Ian.
Oscifer
Member
Member
Posts: 6
Joined: July 26th, 2013, 10:50 pm

Re: Webmin Cron Job issues

Post by Oscifer »

Here is the script:

Code: Select all

# PURPOSE: Script to check temperature of CPU cores and report/shutdown if specified temperatures exceeded
#
# AUTHOR: feedback[AT]HaveTheKnowHow[DOT]com

# Expects two arguments:
#    1. Warning temperature
#    2. Critical shutdown temperature
#    eg. using ./CPUTempShutdown.sh 30 40
#        will warn when temperature of one or more cores hit 30degrees and shutdown when either hits 40degrees.

# NOTES:
# Change the strings ">>/home/htkh" as required
# Substitute string "myemail@myaddress.com" with your own email address in the string which starts "/usr/sbin/ssmtp myemail@myaddress.com"

# Assumes output from sensors command is as follows:
#
# coretemp-isa-0000
# Adapter: ISA adapter
# Core 0:      +35.0 C  (high = +78.0 C, crit = +100.0 C)
#
# coretemp-isa-0001
# Adapter: ISA adapter
# Core 1:      +35.0 C  (high = +78.0 C, crit = +100.0 C)
#
# if not then modify the commands str=$(sensors | grep "Core $i:") & newstr=${str:14:2} below accordingly

echo "JOB RUN AT $(date)"
echo "======================================="

echo ''
echo 'CPU Warning Limit set to => '$1
echo 'CPU Shutdown Limit set to => '$2
echo ''
echo ''

sensors

echo ''
echo ''

for i in 0 1
do

  str=$(sensors | grep "Core $i:")
  newstr=${str:17:2}

  if [ ${newstr} -ge $1 ]
  then
    echo '============================'                             >>/home/user/MyScripts/CPUWarning.Log
    echo $(date)                                                    >>/home/user/MyScripts/CPUWarning.Log
    echo ''                                                         >>/home/user/MyScripts/CPUWarning.Log
    echo ' WARNING: TEMPERATURE CORE' $i 'EXCEEDED' $1 '=>' $newstr >>/home/user/MyScripts/CPUWarning.Log
    echo ''                                                         >>/home/user/MyScripts/CPUWarning.Log
    echo '============================'                             >>/home/user/MyScripts/CPUWarning.Log
    /usr/sbin/ssmtp user@gmail.com </home/user/MyScripts/msg2.txt
    echo 'Email Sent.....'
  fi

  if [ ${newstr} -ge $2 ]
  then
    echo '============================'
    echo ''
    echo 'CRITICAL: TEMPERATURE CORE' $i 'EXCEEDED' $2 '=>' $newstr
    echo ''
    echo '============================'
    /usr/sbin/ssmtp user@gmail.com </home/user/MyScripts/msg.txt
    echo 'Email Sent.....'
    /sbin/shutdown -h now
    exit
  else
    echo ' Temperature Core '$i' OK at =>' $newstr
    echo ''
  fi
done

echo 'Both CPU Cores are within limits'
echo ''
Oscifer
Member
Member
Posts: 6
Joined: July 26th, 2013, 10:50 pm

Re: Webmin Cron Job issues

Post by Oscifer »

Output from 50 80

Code: Select all

user@NAS:~/MyScripts$ ./CPUTempShutdown.sh 50 80
JOB RUN AT Sat Jul 27 15:25:54 MDT 2013
=======================================

CPU Warning Limit set to => 50
CPU Shutdown Limit set to => 80


acpitz-virtual-0
Adapter: Virtual device
temp1:        +27.8°C  (crit = +103.0°C)
temp2:        +29.8°C  (crit = +103.0°C)

coretemp-isa-0000
Adapter: ISA adapter
Physical id 0:  +30.0°C  (high = +82.0°C, crit = +102.0°C)
Core 0:         +30.0°C  (high = +82.0°C, crit = +102.0°C)
Core 1:         +29.0°C  (high = +82.0°C, crit = +102.0°C)



 Temperature Core 0 OK at => 30

 Temperature Core 1 OK at => 29

Both CPU Cores are within limits

user@NAS:~/MyScripts$
User avatar
Ian
Moderator
Posts: 752
Joined: January 1st, 2011, 7:00 am

Re: Webmin Cron Job issues

Post by Ian »

Thanks :thumbup:

In your script you need to insert the following line at the top of the script. On line #1

Code: Select all

#!/bin/bash
So, the first few lines of your script should now read as follows

Code: Select all

#!/bin/bash

# PURPOSE: Script to check temperature of CPU cores and report/shutdown if specified temperatures exceeded
#
# AUTHOR: feedback[AT]HaveTheKnowHow[DOT]com
Then try and run it from webmin again.

Ian.
Oscifer
Member
Member
Posts: 6
Joined: July 26th, 2013, 10:50 pm

Re: Webmin Cron Job issues

Post by Oscifer »

That fixed it! Thanks for the help. Just out of curiosity, what exactly did that do?
User avatar
Ian
Moderator
Posts: 752
Joined: January 1st, 2011, 7:00 am

Re: Webmin Cron Job issues

Post by Ian »

When you're using your server interactively your logon has certain defaults. One of these defaults is which "shell" (command-line interpreter) to use, in our case "Bash". When you run a job via CRON it has different defaults including which shell to use. Specifying #!/bin/bash ensures it uses the same shell however you run it.

Ian.
Oscifer
Member
Member
Posts: 6
Joined: July 26th, 2013, 10:50 pm

Re: Webmin Cron Job issues

Post by Oscifer »

Ok! I appreciate the help and thanks for the info.
Post Reply