[ale] [OT] how do I monitor the "weather" in my computer room

Scott Plante splante at insightsys.com
Fri Jun 7 14:04:30 EDT 2013


You can clean up your script and save yourself some typing by replacing this style: 


cmd1 > file 
cmd2 >> file 
cmd3 >> file 

with 


{ 
cmd1 
cmd2 
cmd3 
} > file 


Also, I don't know if this is a box you have root on, but you can eliminate storing your password in pw.txt by adding specific commands to your sudoers file with "NOPASSWD:". This can be apropriate for certain commands like yours that are just reporting data. For example, I added this line with visudo: 
splante ALL=(root) NOPASSWD: /usr/sbin/hddtemp 

And now I can execute this command without a password: 

sudo /usr/sbin/hddtemp /dev/sda 


Other commands you may want the safety of having to type the password each time, but if you have the password in a text file you've defeated that purpose anyway. Another alternative would be to run the script that generates the file in root's crontab. 


Scott 
----- Original Message -----

From: "Ron Frazier (ALE)" <atllinuxenthinfo at techstarship.com> 
To: "Atlanta Linux Enthusiasts" <ale at ale.org> 
Sent: Thursday, June 6, 2013 11:38:23 PM 
Subject: Re: [ale] [OT] how do I monitor the "weather" in my computer room 

Hi Scott, Alex, and all, 

Thanks for the recent suggestions. I now have a crude and rude, quick 
and dirty, and somewhat ugly solution running. But ... it is running, 
which is very cool. Anyone is welcome to use these scripts. 

I first created a script to read the sensors and create a simple crude 
html data file. I didn't worry with tables. I just use raw text and 
paragraph markers. The hddtemp command must run as sudo, and pulls its 
password from a text file. I don't know if that's the best way to 
handle it or not, but it works. 

----------------- 

checktemps file 

#!/bin/bash 
cd ~ 

echo '<html>' > temperature.html 


echo 'Bugs01 Temperatures' >> temperature.html 
echo '<p>' >> temperature.html 

date >> temperature.html 
echo '<p>' >> temperature.html 

echo 'CPU - ' >> temperature.html 
sensors | grep 'temp1' >> temperature.html 
echo '<p>' >> temperature.html 

echo 'HDD1 - ' >> temperature.html 
sudo -S hddtemp /dev/sda < pw.txt >> temperature.html 
echo '<p>' >> temperature.html 

echo 'HDD2 - ' >> temperature.html 
sudo -S hddtemp /dev/sdb < pw.txt >> temperature.html 
echo '<p>' >> temperature.html 

echo 'GPU0 - ' >> temperature.html 
sudo aticonfig --adapter=0 --odgt >> temperature.html 
echo '<p>' >> temperature.html 

echo 'GPU1 - ' >> temperature.html 
sudo aticonfig --adapter=1 --odgt >> temperature.html 
echo '<p>' >> temperature.html 

echo 'GPU2 - ' >> temperature.html 
sudo aticonfig --adapter=2 --odgt >> temperature.html 
echo '<p>' >> temperature.html 


echo '</html>' >> temperature.html 

---------------- 

By the way, even though scripts run without an extension in the file 
name, is it normal to use an extension? 

I then execute the checktemps script every 15 seconds with: 

watch -n 15 ./checktemps 

Then I use the nc command (starting it by hand) to serve up the data 
file when requested on a port number other than the default. This must 
also run as sudo: 

while true; do sudo nc -l 56789 < ./temperature.html; done 

I enter the following address of my basement computer in a web browser 
on the same subnet: 

http://192.168.81.134:56789/ 

I get the following: 

--------------------- 

browser result on special port 

<html> 
Bugs01 Temperatures 
<p> 
Thu Jun 6 22:57:36 EDT 2013 
<p> 
CPU - 
temp1: +43.0°C (high = +70.0°C) 
<p> 
HDD1 - 
/dev/sda: ST9320320AS: 25°C 
<p> 
HDD2 - 
/dev/sdb: ST95005620AS: 27°C 
<p> 
GPU0 - 

Adapter 0 - AMD Radeon HD 7800 Series 
Sensor 0: Temperature - 82.00 C 
<p> 
GPU1 - 

Adapter 1 - AMD Radeon HD 6700 Series 
Sensor 0: Temperature - 79.00 C 
<p> 
GPU2 - 

Adapter 2 - AMD Radeon HD 7800 Series 
Sensor 0: Temperature - 70.00 C 
<p> 
</html> 

----------------- 

So, it works. What's weird is that it's actually showing the source 
text of the html file. However, if I do the same thing on port 80, it 
actually formats as a web page and looks like this: 

browser result on port 80 

Bugs01 Temperatures 

Thu Jun 6 23:18:55 EDT 2013 

CPU - temp1: +43.0°C (high = +70.0°C) 

HDD1 - /dev/sda: ST9320320AS: 25°C 

HDD2 - /dev/sdb: ST95005620AS: 28°C 

GPU0 - Adapter 0 - AMD Radeon HD 7800 Series Sensor 0: Temperature - 81.00 C 

GPU1 - Adapter 1 - AMD Radeon HD 6700 Series Sensor 0: Temperature - 81.00 C 

GPU2 - Adapter 2 - AMD Radeon HD 7800 Series Sensor 0: Temperature - 71.00 C 

-------------------- 

So, I'm getting there. There are still a few problems though: 

A) If I let nc run on port 80, I get a properly displayed web page in 
the browser. If I don't, I get a display as if I'm looking at the page 
source. 

B) The sudo authorization for the nc command expires and then my web 
page no longer loads. 

C) I don't have an autostart sequence running yet. 

D) Sometimes, if I happen to retrieve the file while it's being written, 
I get an incomplete result. 

E) I cannot CTRL-C to terminate the window with the nc running in it. I 
have to force close that window. 

Anyway, like I said, getting there. 

Any further suggestions are appreciated. 

Sincerely, 

Ron 


-- 

(PS - If you email me and don't get a quick response, you might want to 
call on the phone. I get about 300 emails per day from alternate energy 
mailing lists and such. I don't always see new email messages very quickly.) 

Ron Frazier 
770-205-9422 (O) Leave a message. 
linuxdude AT techstarship.com 
Litecoin: LZzAJu9rZEWzALxDhAHnWLRvybVAVgwTh3 
Bitcoin: 15s3aLVsxm8EuQvT8gUDw3RWqvuY9hPGUU 

_______________________________________________ 
Ale mailing list 
Ale at ale.org 
http://mail.ale.org/mailman/listinfo/ale 
See JOBS, ANNOUNCE and SCHOOLS lists at 
http://mail.ale.org/mailman/listinfo 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20130607/3c4e6d33/attachment.html>


More information about the Ale mailing list