Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm trying this script out but, I don't know enough about how it works to figure out what's causing the problem. I'm not having a lot of luck googling. OS is ubuntu 11.10.
SCRIPT:
Code:
#!/bin/bash
HDDS="/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde"
HDT=/usr/sbin/hddtemp
LOG=/usr/bin/logger
DOWN=/sbin/shutdown
ALERT_LEVEL=55
for disk in $HDDS
do
if [ -b $disk ]; then
HDTEMP=$($HDT $disk | awk '{ print $4}' | awk -F '°' '{ print $1}')
if [ $HDTEMP -ge $ALERT_LEVEL ]; then
$LOG "System going down as hard disk : $disk temperature $HDTEMP°C crossed its limit"
sync;sync
$DOWN -h 0
fi
fi
done
ERROR:
Code:
daisy@mediaserver:~$ sudo ./tempcheck.sh
./tempcheck.sh: line 15: [: -ge: unary operator expected
./tempcheck.sh: line 15: [: -ge: unary operator expected
./tempcheck.sh: line 15: [: -ge: unary operator expected
./tempcheck.sh: line 15: [: -ge: unary operator expected
daisy@mediaserver:~$
The script is fine, the only issue is that $HDTEMP is not defined when the if statement is hit.
Here is an alternative way to get the temperature:
Code:
smartctl -A /dev/sda | grep Temperature_Celsius | awk '{ print $10 }'
OR
smartctl -A /dev/sda | grep Airflow_Temperature_Cel | awk '{ print $10 }'
Also, the HDD temperature is not too important. I mean, I don't see any reason for the HDD to overheat, not any reason to shutdown if it does. Just make sure there is room around the HDD inside the case and it should be fine.
Last edited by H_TeXMeX_H; 09-16-2012 at 04:05 AM.
That's kinda of the problem. It's an older dell tower pc with really crappy ventilation. Two of the drives are constantly ranging from 50°-60° and I'm not so cool with that. It seriously decreases the lifespan of the drive and it gets annoying to have to RMA one every 6 months. Since it's a media server, I prefer it to be constantly at the ready but, since I'm not home 75% of the day, I'd rather it turn off if it gets too hot than turn it off, turn it on, turn it off, turn it on several times a day.
back to the code: It seems to me that HDTEMP is defined--right before the if statement that tests it.....but yes, if it's not defined, that causes the error.
But--BUT--maybe it's getting set to a string and not to a number?
try to use set -xv, so you will get much more info about what's happening (set -xv should be inserted as the second line of the script). In general you need to use " with variables, so better to write: if [ -b "$disk" ]; then and if [ "$HDTEMP" -ge "$ALERT_LEVEL" ]; then
You may need to try a better approach to find out the temperature, so you can try this: HDTEMP=$($HDT $disk | awk '{ match($4, "[0-9]+", a); print a[0]}')
Also using the idea from H_TeXMeX_H you can try: HDTEMP=$(smartctl -A $disk | awk '/Temperature_Celsius/ { print $10 }')
Since environment variables are generally all upper-case, it's good practice to keep your own user variables in lower-case or mixed-case to help differentiate them.
When using bash or ksh, it's recommended to use [[..]] for string/file tests, and ((..)) for numerical tests. Avoid using the old [..] test unless you specifically need POSIX-style portability.
#!/bin/bash
alert_level=55
hdds=( /dev/sd{a,b,c,d,e} )
hdt() {
/usr/sbin/hddtemp "$1" | awk '{ print int($NF) }'
}
log() {
/usr/bin/logger "System going down as hard disk : $1 temperature $2°C crossed its limit"
}
down() {
/sbin/shutdown -h 0
}
for disk in "${hdds[@]}"; do
if [[ ! -b $disk ]]; then
echo "Unknown device type: $disk. Skipping"
continue
fi
hdtemp=$( hdt "$disk" )
if (( hdtemp >= alert_level )); then
log "$disk" "$hdtemp"
sync
sync
down
fi
done
And as mentioned, you could just skip the array completely and use this:
Code:
for disk in /dev/sd[a-e]; do
This would also remove the need for the "-b" test, since you'll only be getting devices that actually exist at the moment.
Last edited by David the H.; 09-16-2012 at 08:43 AM.
Reason: small code corrections
thanks for all the replies! unfortunately, most of it was over my head but I'll try to pick it up. I went with David the H's idea and it seems to work. Is there any way to output what it does to a log so I can verify it's working? @pixellany: there is no more room/no more juice from the power supply for any more fans. I've added tons. I really need a new machine but I'm being cheap.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.