Just taking a moment to geek out. I finished my arduino code for my home HVAC project and decided to give it a burn in test tonight. I have 5 DS18S20 temperature sensors connected via parasitic 1-wire to pin 10 on a boarduino. My code just goes out and does a beacon looking for any 1-wire devices on the network and then queries them. It takes that data, turns it from hex to a Fahrenheit temperature and then prints a colon delimited string with that information out onto the serial port. I had been using just 1 probe, so tonight I decided for giggles to hot add 4 more. I smacked the ICs onto the breadboard while everything was running and what do you know, the code picked the new units up and never skipped a beat! Cool!
This assumes you’ve already run the convert spaces script. The following script will use mplayer and lame to convert WMAs to MP3s. Not much to talk about here. The wma is dumped to a wav which is then encoded in lame. You’ll end up with WMAs and MP3s of your music and you can pick and choose what you would like to do with them.
for i in `find ./ -type f |grep -i .wma`; do
mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader $i && lame -m s out.wav -o $i;
cp “$i” “`basename “$i” .wma`.mp3″
rm out.wav
done
Windows file names can be really frustrating, so I found a script on the web that recurses a directory and replaces every space it finds with an underscore. Good stuff.
IFS=’
‘
#rename direcotories
for (( i=0; i<=j ; i++ )); do
for name in `find -mindepth $i -maxdepth $i -iname "* *" -printf "%p\n"`; do
newname=`echo "$name" | tr " " "_"`;
echo "$name" "$newname";
mv "$name" "$newname";
done;
done
#rename files
for name in `find ./ -iname "* *" -printf "%p\n"`; do
newname=`echo "$name" | tr " " "_"`
echo "$name" "$newname"
mv "$name" "$newname"
done
Sometimes, code isn’t written to be especially portable and requires some hand editing to coax it to run on a new machine. A shortcut that I’m fond of using is to set off a perl script to search for every instance of $WORD inside of $FILE. So if I wanted to replace every instance of “jason” inside of all of the files that are “.html” with the word “dude” I would use the following.
perl -pi -e ‘s/jason/dude/g’ *.html
To make that caps insensitive, run it like so
perl -pi -e ‘s/jason/dude/gi’ *.html
While I have a good monitoring system setup, some of my nodes can’t be monitored and require manual checkups. To speed things up, I use a little bash script to log into each host and check a few things out. This snippit below walks through each host in my host file and prints out file systems that are at greater then 90% utilization.
for i in `cat /etc/hosts | grep -v localhost | awk {‘print $3′}`; do
echo $i;
ssh $i “df -k | sed 1d | awk ‘\$5>90 {print}’”;
done