Posts Tagged awk

Tux

This was my first post in my private blog..Tux

I was browsing through images of Tux in Google. Just thought, why don’t i write a script that keeps changing my background image every few minutes? Got into action sometime last week. Wrote a small script that changes gconf entry. The script was done. I had learnt a little bit of awk by the time i completed the script.

Setting up the script in crontab created some issues. Took a long time to resolve my silly mistakes like ending statements with ; in scripts :-) . The following are the links that helped me learn more about crontab.

http://reallylinux.com/docs/basiccron.shtml
http://www.adminschoice.com/docs/crontab.htm
http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/

And this is my small script: changemytux.sh

dir=$HOME/tux
cd $dir
old=$(gconftool-2 -g /desktop/gnome/background/picture_filename)
count=$(ls -1 $dir/*.png $dir/*.jpg | wc -l)
if [ $count -lt 2 ]; then
exit 1
fi
while :
do
rn=$(($RANDOM%$count+1))
new=$(ls -1 *.png *.jpg | sort | awk -v rd="$rn" 'NR==rd {print $1}')
new=$dir"/"$new
if [ "$new" != "$old" ]; then
break
fi
done
/opt/gnome/bin/gconftool-2 -s /desktop/gnome/background/picture_filename -t string $new

At the end of the day, I had learnt awk, something about crontab and not to end all statements with semicolon;

Comments (1)