Tuesday, March 17, 2009

Birthday Reminder For Gnome Panel

This program checks the file /home/rsrijith/shell/birthday_reminder.txt to find the upcoming birthdays in 20 days and writes into the file /home/rsrijith/shell/birthdays.
There is a file called /home/rsrijith/shell/birthdays1, the difference between it and birthdays file is that birthdays contains only first name of the person and birthdays1 contains the whole name.
So that's it. Now the code....
#!/bin/bash
echo "Birthday Finder ">>/home/rsrijith/logs/bday
date>>/home/rsrijith/logs/bday
tillm=$(date --date="+20 day" +"%b")
nowm=$(date +"%b")
tilld=$(date --date="+20 day" +"%2d")
nowd=$(date +"%d")
nowd=$((10#$nowd))
year=$(date +"%Y")
FileName='/home/rsrijith/shell/birthday_reminder.txt'
if [ -e /home/rsrijith/shell/birthdays ]
then
rm /home/rsrijith/shell/birthdays
fi
touch /home/rsrijith/shell/birthdays
if [ -e /home/rsrijith/shell/birthdays1 ]
then
rm /home/rsrijith/shell/birthdays1
fi
touch /home/rsrijith/shell/birthdays1
while read LINE
do
m=$(echo $LINE|cut -f2 -d',')
d=$(echo $LINE|cut -f3 -d',')
name=$(echo $LINE|cut -f1 -d',')
yob=$(echo $LINE|cut -f4 -d',')
if [ $m == $nowm ]
then
d="${d#0}";
if [ $nowd -le $d ]
then
name1=$name;
name=` echo $name|sed 's/\([^ ]*\).*/\1/;s/\([^.]*\).*/\1/'`
dif=$(($d-$nowd))
yrdif=$(($year-$yob))
if [ $dif -le 1 ]
then
if [ $dif -eq 0 ]
then
echo "Happy Birthday to "$name>>/home/rsrijith/shell/birthdays
echo "Happy Birthday to "$name1>>/home/rsrijith/shell/birthdays1
else
echo "$dif day to "$name"'s Birthday">>/home/rsrijith/shell/birthdays
echo "$dif day to "$name1"'s Birthday">>/home/rsrijith/shell/birthdays1
fi
else
echo "$dif days to "$name"'s Birthday">>/home/rsrijith/shell/birthdays
echo "$dif days to "$name1"'s Birthday">>/home/rsrijith/shell/birthdays1
fi

fi
else
if [ $m == $tillm ]
then
if [ $tilld -gt $d ]
then
name1=$name
name=` echo $name|sed 's/\([^ ]*\).*/\1/'`
lastdate=$(date -d "-$(date +%d) days +1 month"|cut -f 3 -d " ")
echo "$d $lastdate $nowd"

dif=$(($d+$lastdate-$nowd))
yrdif=$(($year-$yob))
echo "$dif days to "$name1"'s Birthday">>/home/rsrijith/shell/birthdays1
echo "$dif days to "$name"'s Birthday">>/home/rsrijith/shell/birthdays
fi
fi
fi
done < $FileName
if [ ! -s /home/rsrijith/shell/birthdays ]
then
echo "Nothing to Remind" > /home/rsrijith/shell/birthdays
fi
cat /home/rsrijith/shell/birthdays1|sort -n >/home/rsrijith/temp && mv /home/rsrijith/temp /home/rsrijith/shell/birthdays1
cat /home/rsrijith/shell/birthdays|sort -n >/home/rsrijith/temp && mv /home/rsrijith/temp /home/rsrijith/shell/birthdays

This code is part of the Perl Panel Code. The related codes to this are:

No comments:

Post a Comment