This little bash script will watch several files for changes and serves as the basis for more complicated scripts that actually do something when a change is detected. It’s simply a matter of comparing the output of stat every 5 seconds

#!/bin/bash

count=0
for var in "$@"; do
    count=$(($count + 1));
    files[$count]=$var;
    stats[$count]=`stat -r "$var"`;
done

while [ true ]; do
    i=1
    while [ $i -le $count ]; do
        newstat=`stat -r "${files[i]}"`
        if [ "$newstat" != "${stats[i]}" ]; then
            echo \"${files[i]}\"
            stats[$i]=$newstat
        fi
        i=$(($i+1))
    done

    sleep 5
done

After discovering I didn’t backup everything on my server before the hard disk was replaced I realized how much I love  procmail, especially the rule that adds a reply-to header to several mailing lists. Technically they aren’t mailinglists but just lists, thanks to Google Apps used by my student association. Fortunately I bragged about it on Facebook several months ago so after checking my old wall posts (not a pleasant job because it was months and months of posts) I found it.

I did fix my backup scripts but just to be sure, and maybe to make someone else happy I’m posting it here:

# Add reply-to to those pesky example.com mailinglists.
:0 fhw
* ^List-Id:\/.*\.example\.com
|formail -I "Reply-To: `echo $MATCH | \
sed -e 's/^.*\>\(.*\)\.example\.com.*$/\1@example.com/'`"

# Other ppl without cool procmail rules press reply-all
# so delete all to <lists>@example.com msgs cc'd to me
:0
* ^TO_(list_name|another_list|yet_another_list)@example.com
* !^List-Id:\/.*\.example\.com
/dev/null

Update: I’ve added a second rule to delete all mail that is addressed to the mailing list (using *@example.com won’t work because there are also non-list adresses at that domain) but has no list-id and therefor must be a cc to me, not the list, because few people have these cool filters and most just press reply-all to make sure it is at least delivered to the list. Sigh. I’m still monitoring this rule in case of errors but it seems to work fine. You can replace /dev/null with your trash folder if you want to be less rigorous.

I don’t pay much attention to my hard disk usage nor do I remember to periodically empty the trash. In fact, I don’t want to empty the trash as long as the disk space is available because you never know when to need to restore a trashed file.

To keep track of my disk usage I made a simple bash script that determines the free space and size of the trash and sends a Growl notification if the disk space is running low or the trash is to big (absolute or proportional to the free space available) and set my crontab to run it every 15 minutes. Continue reading »

GeekTool DesktopThe past couple of days I’ve been playing around with GeekTool a nifty litlle application that can show text files, unix commands output (including scripts), or images (local and from the internet) on your desktop.  There are many sites with examples out there which inspired me to create a GeekTool setup of my own.

I started playing around with several scripts and GeekTool because it looked cool at first and it was fun to do some shell scripting. As the amount of information displayed on my desktop grew I started wondering why I was creating a lot of small processes taking up a little CPU time. I hardly ever look at my desktop because of all the windows in front of it. But the stats now on my desktop are easily accesable with one key (F11), and some starts are already displayed in either the menu bar or my iStat Pro widget. Removing it there gives me more room in the menu bar (which is starting grow full of icons) and saves some resources used by the widget.

Now I shall explain the GeekTool entries I created more detailed.

Continue reading »

The svn commandline tool is great, but when I don’t receive a e-mail notifying me of a new commit I hardly ever read the log messages. That’s why I added an alias to my profile called svnup which does an update and then prints the log from the revision before the update to now.

SVN_CURR_REV=`svn info|grep 'Last Changed Rev'|awk '{ print $4 }'`; \
svn up; \
svn log -r $SVN_CURR_REV:HEAD

Now I just have to remember tot type svnup instead of svn up.

© 2011 Ronald! Suffusion theme by Sayontan Sinha