Linux Blog

APC Access Temperature Query and Conversion. (2 of 2)

Filed under: Shell Script Sundays — TheLinuxBlog.com at 6:55 pm on Sunday, March 29, 2009

This second part of the script APC Access Temperature Query Script and its been a long time coming. Basically this script is the part that runs as a cron and will e-mail me if the temperature goes over a certain threshold. Once it returns to normal it e-mails me again. It has the option to send a text message to me via my SMS gateway, but it is commented out.

#!/bin/bash

temp=$(/home/linux/bin/temp f)
threshold=76

if [ "`echo \"$temp > $threshold\" | bc`" == 1 ]; then
echo $(date +%s) $temp >> /home/linux/thermal-over.log
echo “High Temp”;

if [ "$(cat temp.txt)" == "norm" ]; then
echo “Sending E-Mail, High Temp”;
echo “Current Temperature Is: $(/home/linux/bin/temp f)” | mail -s “Thermal Overload” owen@linuxblog                #echo “Current Temp Is: $(/home/linux/bin/temp f)” | mail -s “Thermal Overload” mynumber@cingularme.com
echo “high” > temp.txt
fi
elif [ "`echo \"$temp < $threshold\" | bc`" == 1 ]; then
echo “Low Temp”;

if [ "$(cat temp.txt)" == "high" ]; then
echo “Temp Resumed, Sending E-Mail”;
echo $(date +%s) Resumed at: $temp | mail -s “Thermal Normal” owen@linuxblog
echo “norm” > temp.txt
fi

fi

echo $(date +%s) $temp >> /home/linux/thermal.log

When I first wrote the script, I did not do any temperature checking. I found out that I needed to when I came back one morning with a bunch of emails that I needed to delete. Its pretty simple to figure out, temp.txt holds a value that is either norm or high. It gets switched when the temperature changes, this will in turn stop it from e-mailing me repeatedly. Once the temperature drops it flips it back. It will still e-mail if your temperature fluctuates between 75 and 77 which can be annoying, but you can adjust the threshold with the variable and set it to what you need. Thankfully our chiller has been fixed and I no longer have to worry about the temperature, but it still runs on a cron just in case.

Getting Home

Filed under: General Linux — TheLinuxBlog.com at 6:30 am on Friday, January 16, 2009

Getting into your home network from the wild west known as the internet can be a pain, especially if your IP address is always changing on you, or perhaps the one time that you need to get into your home network your IP address changed.

This happened to me not so long ago, my IP address hardly ever changes but my IP address did happen to change when I moved into my new residence. Assuming that my address would stay the same I headed off to work, unfortunately I was unable to phone home.

Many people know about the free sites that let you update your IP address such as DynDNS, no-ip.org etc. But I couldn’t settle for that mediocre domain. By setting up a CNAME in my DNS I was able to forward a subdomain to my dynamic update address which in effect allowed me to remember home.mydomainname.com rather than the wacky no-ip.org address I chose. You can do the same using free utilities, providing that you have a little time and some control over your DNS.

Before you proceed make sure you have a way of setting a CNAME for your domain name. You can try your domain registrant if you use their web servers, maybe your web host gives you the ability to manage zones and if not ask them if they can add it for you, most times they will.

You will need to set up an account with one of the free providers I used No-IP.com but others like DynDNS.org, freedns.afraid.org, ZoneEdit.com and easyDNS.com should work.

Once you have set up an account with them and have your IP address mapped to a domain name, go ahead and add the CNAME record into your DNS.

The next step is to install and configure the program, script, cron or whatever method your free DNS account uses to update. I used my DD-WRT installation and plugged my account information into the DDNS tab, I checked the update and it registered my IP.

Once you have got your IP address into the free DNS provider, you should check to make sure that it works by doing a lookup on that host name. Use nslookup to do this:

nslookup yoursubdomian.your-free-dns-account.com

If it resolves to your home IP address, then your set to move forward with tackling the task of adding the CNAME into the DNS for your domain name. I cannot cover how to do this with every system in this article but basically you create a zone with the domain, 14400 IN CNAME and the full address of your free DNS with a period at the end. This is important or your name will not resolve properly.

Depending on what DNS servers you use it may take a while for the DNS to get updated. In nslookup I set my server to use OpenDNS’s in to test to make sure the name resolved properly. To do this, start nslookup and type:

> server 208.67.222.222

Once you perform a lookup on your new subdomain, you should see something like the following:

> home.yourdomainname.com

Server: 208.67.222.222

Address: 208.67.222.222#53

Non-authoritative answer:

home.yourdomainname.com canonical name = yoursubdomain.your-free-dns-account.com

Name: yoursubdomain.your-free-dns-account.com

Address: <your IP>

Thats all there is to it. If your IP is updating via your free DNS service and you set up your CNAME then you will be able to find your home, or give your home address to anyone wishing connect without the embarrassment or hassle of explaining your subdomain and free domain account.

sl the BOFH’s revenge for bad typists

Filed under: Linux Software — TheLinuxBlog.com at 9:57 am on Wednesday, November 19, 2008

If you don’t know what BOFH is, then lets try wikipedia. This morning in my feed reader from tips4linux.com was an article that “makes you pay attention.”

Basically, the article software package they were recommending today is sl. I couldn’t resist commenting on this. There are many times that I am stuck over a slow SSH session, all I need is the server admin, or BOFH coming along, installing sl and making my life a pain.

So, I installed it on my desktop. What an excellent piece of software. If you run Fedora its in the yum repos and you should give it a shot. Now, all I have to do is symlink this to other useful binaries that I commonly mistype, don’t have installed and for good operator measures, some that I do.

Its too bad that I couldn’t run this through wall, but I guess I could run it as a cron. I think it should have a config file so that you could work it a bit more. Perhaps as it steams through make the smoke spell a message. Any way, thats my ranting and rambling over for the morning. Now to yum remove.

Suspend Scripts for the Toshiba Tecra M2

Filed under: Quick Linux Tutorials,Shell Script Sundays — TheLinuxBlog.com at 12:15 am on Sunday, March 30, 2008

As you may know if you are a regular reader I own a Toshiba Tecra M2. One of the things that annoyed me was I had to turn the brightness up every time my computer came out of standby mode. A fix for this is to adjust the brightness every time the computer comes out of standby mode.

The script is intended to be run under cron. I have mine set up to suspend after 5 minutes of the lid being closed.

if [ $(cat /proc/acpi/button/lid/LID/state | sed 's/state:      //') == "closed" ]; then
VAR=$(cat /proc/acpi/toshiba/lcd | sed ‘s/brightness:              //’ grep -v levels);
sudo su -c “echo mem > /sys/power/state”;
if [ $VAR -eq 1 ]; then
ACTION=ADD;
elif [ $VAR -eq 7 ]; then
ACTION=SUB;
else
ACTION=ADD;
fi;
if [ $ACTION == "ADD" ]; then
VAR=$(($VAR + 1));
else
VAR=$(($VAR – 1));
fi;
sudo su -c “echo brightness:$(echo $VAR) > /proc/acpi/toshiba/lcd”;
fi;

I run this with the following cron entry:

*/5 * * * * sh hibernate.sh

The script first checks the current brightness. If the brightness is currently 1 or 7 it adjusts the mathematic operation so that when the laptop is opened the brightness is adjusted. Basically if the brightness is one, it adds one. If the brightness is 7 or any other value it subtracts one. This is currently working out quite well for me. I don’t know how useful this is to any body else, unless you happen to have a Toshiba that is doing the same thing but it should give you a good overall idea of how to perform basic mathematic operations in bash.

Snippet: Keeping SSH Running

Filed under: Quick Linux Tutorials,Shell Script Sundays — TheLinuxBlog.com at 12:53 am on Sunday, November 4, 2007

I wrote a post not so long back called Bringing The Internet Up After Failure that explained how I was restarting my network services after the internet went down.

Shortly after this I was remotely working when I thought it would be a good idea to restart my SSHD to enable X11 forwarding. After running the script that normally restarts the service I tried to reconnect. Unfortunately the service never restarted after being stopped. This is not a good situation for any one to be in so I added something like this to my cron along at the end of my network services script:

ps ax | grep \usr\/sbin\/sshd | grep Ss && echo “SSHD Running” || echo “Starting SSH”; sudo /etc/rc.d/rc.sshd start

The only difference between the version I am running and the version above is that I don’t echo anything out. All the command does is use the ps command and grep for usr/sbin/sshd then grep for the STAT field of sS. I do this because sshd shows up in the process list as shown below:

owen@the-linux-blog$ ps ax | grep sshd
3463 pts/0 R+ 0:00 grep sshd

The rest is self explanitory, it echo’s “SSHD Running” or sudo starts the SSHD.

If SSHD ever terminates on me or those of us who run this snippet we will be able to rightfully regain access to our systems, Hurray!