Archive for March, 2006
the power of SH

One of my favorite things about *nix flavored Operating Systems is the power of the “base system.” It has never been the extremely complex components that fascinate me the most, but rather the small things which a lot of people never use. Anyway, one example would be long but effective shell commands such as the following, which is only a small part of a homegrown backup script:

for FILE in `find /usr/backups/ -type f -name "????-??-??-*.bz2" -mtime +60`; do
    if [ `echo $FILE | egrep "[[:digit:]]{4}-[[:digit:]]{2}-[0,2]6-"` ]; then
        echo "===> IGNORING: $FILE"
    else
        ls -l $FILE && rm $FILE
    fi
done

These are the types of things which make administering servers fun and easy—and there is something really satisfying about writing out a sort of shell script and then watching it work exactly as it should, even if it takes a few tries.