{"id":30,"date":"2017-01-25T12:37:37","date_gmt":"2017-01-25T12:37:37","guid":{"rendered":"http:\/\/owncloud.gonscak.sk\/?p=30"},"modified":"2017-01-25T12:37:37","modified_gmt":"2017-01-25T12:37:37","slug":"kontrola-teploty-fyzickych-servra-a-mail-notifikacia-po-prekroceni-limitu","status":"publish","type":"post","link":"https:\/\/www.gonscak.sk\/?p=30","title":{"rendered":"Periodically check temp of hdd"},"content":{"rendered":"<p>This is a little how to. Its periodically in cron checking temperature of internal hard-disk and in some condition make an alert by mail.<br \/>\nSo, as always, install some useful packages:<\/p>\n<pre><code>yum install epel-release.noarch\nyum install htop dstat lm_sensors.x86_64 hddtemp<\/code><\/pre>\n<p>First, we must check, which disk we have inside. We use only paragraph without numbers:<\/p>\n<pre>ls -lah \/dev\/sd*\n----------------\nbrw-rw---- 1 root disk 8,\u00a0 0 Dec\u00a0 1 07:20 \/dev\/sda\nbrw-rw---- 1 root disk 8,\u00a0 1 Dec\u00a0 1 07:20 \/dev\/sda1\nbrw-rw---- 1 root disk 8, 16 Dec\u00a0 1 07:20 \/dev\/sdb\nbrw-rw---- 1 root disk 8, 17 Dec\u00a0 1 07:20 \/dev\/sdb1\nbrw-rw---- 1 root disk 8, 32 Dec\u00a0 1 07:20 \/dev\/sdc\nbrw-rw---- 1 root disk 8, 33 Dec\u00a0 1 07:20 \/dev\/sdc1\nbrw-rw---- 1 root disk 8, 48 Dec\u00a0 1 07:20 \/dev\/sdd\nbrw-rw---- 1 root disk 8, 49 Dec\u00a0 1 07:20 \/dev\/sdd1\nbrw-rw---- 1 root disk 8, 64 Dec\u00a0 1 07:20 \/dev\/sde\nbrw-rw---- 1 root disk 8, 65 Dec\u00a0 1 07:20 \/dev\/sde1\nbrw-rw---- 1 root disk 8, 80 Dec\u00a0 1 07:20 \/dev\/sdf\nbrw-rw---- 1 root disk 8, 81 Dec\u00a0 1 07:20 \/dev\/sdf1\n-----------------\nwe user only:\n\/dev\/sda, \/dev\/sdb, \/dev\/sdc, \/dev\/sdd, \/dev\/sde, \/dev\/sdf<\/pre>\n<p>Create a folder, maybe like this:<\/p>\n<pre>mkdir \/root\/hddtemp<\/pre>\n<p>Create a script to check this temperatures, end some conditions:<\/p>\n<pre>#! \/bin\/bash\n#written by vasil\nHDDS=\"\/dev\/sda \/dev\/sdb \/dev\/sdc \/dev\/sdd \/dev\/sde \/dev\/sdf\"\nHDT=\/usr\/sbin\/hddtemp\nmail=\"\/root\/hddtemp\/messagebody.txt\"  #file for messasege by mail\nLOG=\/root\/hddtemp\/hddtemp.log         #log file\nALERT_LEVEL=48                        #temperature treshold\ndate &gt;&gt; $LOG\necho \"Subject: \"WARNING - name-of-server - temperature of hdds is high\"\" &gt; $mail\necho \" \" &gt;&gt; $mail\ndate &gt;&gt; $mail\nm=0\nfor disk in $HDDS\ndo\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 HDTEMP=$($HDT $disk | awk -F \":\" '{ print $3}' | awk -F \"\u00b0\"\u00a0 '{print $1}')\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if [ $HDTEMP -ge $ALERT_LEVEL ];\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 then\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo \"Temperature of disk $disk is higher then limit $ALERT_LEVEL celsius\" &gt;&gt; $LOG\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo \"Temperature of disk $disk is higher then limit $ALERT_LEVEL celsius\" &gt;&gt; $mail\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $HDT $disk &gt;&gt; $LOG\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $HDT $disk &gt;&gt; $mail\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo \" \" &gt;&gt; $LOG\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo \" \" &gt;&gt; $mail\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 m=1\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo \"Temperature of disk $disk Is normal: $HDTEMP celsius\" &gt;&gt; $LOG\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n                                echo \"Temperature of disk $disk Is normal: $HDTEMP celsius\" &gt;&gt; $mail\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fi\ndone\nif [ \"$m\" -ne \"0\" ];\nthen\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sh \/root\/hddtemp\/send_mail_script.sh\nelse\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo\nfi\necho \"end of script....\" &gt;&gt; $LOG\necho \" \" &gt;&gt; $LOG\nexit 0<\/pre>\n<p>Next, we must create a script, to send mail to us, if we have a mail server in local network with allowed port 25:<\/p>\n<pre>vim \/root\/hddtemp\/send_mail_script.sh\n#!\/bin\/bash\n#written by vasil\n#\n#if there is an error in syntax \"sendmail\", configure \/etc\/ssmtp\/ssmtp.conf\n#\n# subject of email\nSUBJECT=\"WARNING - name-of-server - temperature of hdds is high\"\n# destination\nEMAIL=\"vasil@gonscak.sk\"\n# Email body\nEMAILMESSAGE=\/root\/hddtemp\/messagebody.txt\n# send message using \/bin\/mail\n#sendmail $EMAIL &lt; $EMAILMESSAGE\n\/usr\/bin\/mail -s \"$SUBJECT\" $EMAIL &lt; $EMAILMESSAGE<\/pre>\n<p>Now, we can test the above scripts. Maybe we must add +x permissions:<\/p>\n<pre>sh -x \/root\/hddtemp\/hddtemp.sh\n------------------------------\n+ HDDS=\/dev\/sda \/dev\/sdb \/dev\/sdc \/dev\/sdd \/dev\/sde \/dev\/sdf\n+ HDT=\/usr\/sbin\/hddtemp\n+ mail=\/root\/hddtemp\/messagebody.txt\n+ LOG=\/root\/hddtemp\/hddtemp.log\n+ ALERT_LEVEL=28\n+ date\n+ echo Subject: WARNING - name-of-server - temperature of hdds is high\n+ echo\n+ date\n+ m=0\n+ \/usr\/sbin\/hddtemp \/dev\/sda\n+ awk -F : { print $3}\n+ awk -F \u00b0 {print $1}\n+ HDTEMP= 38\n+ [ 38 -ge 28 ]\n+ echo Temperature of disk \/dev\/sda is higher then limit 28 celsius\n+ echo Temperature of disk \/dev\/sda is higher then limit 28 celsius\n+ \/usr\/sbin\/hddtemp \/dev\/sda\n+ \/usr\/sbin\/hddtemp \/dev\/sda\n+ echo\n+ echo\n+ m=1\n+ \/usr\/sbin\/hddtemp \/dev\/sdb\n+ awk -F : { print $3}\n+ awk -F \u00b0 {print $1}\n+ HDTEMP= 35\n+ [ 35 -ge 28 ]\n+ echo Temperature of disk \/dev\/sdb is higher then limit 28 celsius\n+ echo Temperature of disk \/dev\/sdb is higher then limit 28 celsius\n+ \/usr\/sbin\/hddtemp \/dev\/sdb\n...\n...\n...\n+ m=1\n+ [ 1 -ne 0 ]\n+ sh \/root\/hddtemp\/send_mail_script.sh\n+ echo end of script....\n+ echo\n+ exit 0<\/pre>\n<p>And then, we have a mail:<\/p>\n<pre>Subject: WARNING - name-of-server - temperature of hdds is high\nThu Jan 26 11:52:20 CET 2017\nTemperature of disk \/dev\/sda is higher then limit 28 celsius\n\/dev\/sda: TOSHIBA DT01ACA100: 37\u00c2\u00b0C\nTemperature of disk \/dev\/sdb is higher then limit 28 celsius\n\/dev\/sdb: ST3500418AS: 35\u00c2\u00b0C\n....<\/pre>\n ","protected":false},"excerpt":{"rendered":"<p>This is a little how to. Its periodically in cron checking temperature of internal hard-disk and in some condition make an alert by mail. So, as always, install some useful packages: yum install epel-release.noarch yum install htop dstat lm_sensors.x86_64 hddtemp First, we must check, which disk we have inside. We use only paragraph without numbers: &hellip; <a href=\"https:\/\/www.gonscak.sk\/?p=30\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Periodically check temp of hdd<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[11,12,13,8,14],"class_list":["post-30","post","type-post","status-publish","format-standard","hentry","category-centos","tag-devsd","tag-check","tag-hddtemp","tag-linux","tag-temp"],"_links":{"self":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/30","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=30"}],"version-history":[{"count":0,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/30\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}