Ugly shell scripting

Recently I developed a strange wear pattern on my car’s front passenger side tire (that’s front rightside tire for those driving on the “wrong” side”) – the outer surface of the tire was warn almost completely bald while the inside treat was fresh and meaty. This was rather odd, as I recently had the car re-aligned with zero toe and max negative camber, which comes out to around -1.6 on both sides. Later I found that as a result of this slight adjustment, I had been pushing the car a lot more aggressively while driving to and from work. The downside of this, as I retraced my steps, is that my drive home from work is almost entirely left turns. When coupled with the fact that I had been recently pushing the car very hard on these left turns, it made sense that I had worn out just the outer edge of the tire.

Since the car is AWD, I didn’t have the option of just replacing that one tire as the difference in tread levels can be harmful to the AWD system. Now here comes the difficult task of finding a single Bridgestone Potenza RE-960/AS Pole Position tire in 225/45/17 so it can be shaved down and mounted.

After some searching I came upon the website BestUsedTires.com – but searching for “Potenza 960” yielded the tire in all sizes but the size I needed. Now, since I’m lazy, how would I automate this search and have my computer notify ME instead of having to manually check every day for the tire I needed?

Continue Reading

Root Login Notification

When administering a Linux server, especially when several people share root access (with sudo, don’t give out that root password!) – it’s important to know when other root users are logged in. This is also a simple form of intrusion detection, since as soon as someone logs into the root shell an email will be dispatched out.

This only happens when the .bashrc file is executed; just using the “sudo” command will not trigger this, but “sudo su – ” will. I also used “chattr +i” to the .bashrc file to set the immutable bit, so the file cannot be modified or changed, not even by the root user. On my server, it also sends a text message to my phone as soon as someone logs in as root. The message will show the username that executed the sudo command, and the IP address that the user is remotely logged in from.

echo -e “`date`\n`who -m –ips|awk ‘{print $1” “$5}’|sed -e ‘s|(||g’ -e ‘s|)||g’ -e ‘s|-|.|g’|cut -d: -f1`” | mail -s “root login alert” [email protected]

Here’s what the script outputs in the message that it emails:

Tue May 18 15:22:23 CDT 2010

username 123.123.123.123

Continue Reading

Automatic Ksplice updates

Here is a little bit of shell script as a crontab that you can use to automate the checking of Ksplice kernel updates.  This particular one does the following:

  1. Activates at midnight every day, server time
  2. Checks if there are updates
  3. If there are updates available to the kernel, to automatically apply the update
  4. Once the update is applied, email the updates applied to the specified email address “[email protected]

This script does not output anything if there are no updates to apply. Happy scripting!

0 0 * * * uptrack=`/usr/sbin/uptrack-upgrade -y`; uptrackCheck=`echo $uptrack | grep -o "Nothing to be done."`; if [[ $uptrackCheck != "Nothing to be done." ]]; then echo "$uptrack" | mail -s "Ksplice kernel upgraded" [email protected]; fi;

Some things that you can do to make it more interesting:

  • Also have it send you a text message on your phone, by emailing the SMS gateway of your service provider
  • Check more often, by modifying the crontab entry (don’t make it too often that you get blacklisted for abuse!)
Continue Reading

MixRiot.com Music Ripper

Here’s a lazy liner that I cooked up to rip music from MixRiot.com – simply replace the URL variable with the page that contains the music and it will dump the music using wget with an MP3 extension!

url=”http://www.mixriot.com/category/essential-mix/browse-show/broadcasts/bbc/radio-1/2009″; IFS=$’\n’;title=();id=();for i in `GET $url | grep FlashVars | egrep -o “mixriot.com%2Faudio%2Fplay%2F[0-9]{4}” | cut -b 30-`; do id=( “${id[@]}” “$i” ); done; for j in `GET $url | egrep -o “<h2><a href=[[:print:]]{1,} title=[[:print:] ]{1,}>[[:print:] ]{1,}</a></h2>” | cut -d\” -f4`; do title=( “${title[@]}” “$j”); done; for (( k = 0 ; k < “${#id[@]}” ; k++ )); do wget -O”${title[$k]}.mp3″ http://www.mixriot.com/audio/play/${id[$k]}; done;

Continue Reading