puflogh300X74.gif

Polarwave's OpenBSD
Tips and Tricks for Newbies

| Important Dates |

| Home | Tips and Tricks | Links | News Feeds | Fun | Contact | Blog (Opens in New Page) |


Birthdays & Other Important Dates

I keep a plain text file in a personal directory with the birthdays of all my relatives
and friends in it. In order not to forget a birthday, I put together a script to query
that text file the first day of each month. Here's what it all looks like:

Okay, this is the sample text file:

Joe Blow: Jan 03
Mr Deeds: Feb 04
Also Knownas: Mar 09
John Doe: Apr 16
Mr Bossman: May 27
Serial Hacker: Jun 11
Kenny Kludge: Jul 22
General Disorder: Aug 14
Corporal Punishment: Sep 03
Major Disaster: Oct 26
Jack Spratt: Nov 07
Shirley Ujest: Dec 09

And this is the script:

#!/bin/sh
# Notify me if there are any birthdays each month

THISMONTH=$(date -j | cut -c 5-7)
BIRTHDAYS=$HOME/personal/birthdays.txt

if cat $BIRTHDAYS | grep -q $THISMONTH;

then
echo # make line spacing for readability
echo "There are birthdays this month!"
echo # same as above
grep $THISMONTH $BIRTHDAYS

else
echo # once again, same as above
echo "No birthdays this month!"

fi
Let's go through the script. First off, the #!/bin/sh simply assigns the shell used.

The notify notation to the right of the # sign is just a commented out note.

THISMONTH assigns the value derived from the date command piped to the cut
command. As it's written, only the 3-letter abbrevation of the month is left in the
output after the cut command runs. E.g., Jul, Sep, Dec, and so on.

BIRTHDAYS has the value of the path to the actual birthdays.txt assigned to it.
This is a personal, arbitrary setting, depending on your own personal needs.

The 'if' conditional is looking for the aforementioned 3-letter month abbreviation. If
it finds it, the 'then' operator sends the script on to echo an informative output and
then grep is rerun to add it's output showing any dates under the current month.
Since I use this routine in a cronjob, the output is emailed to me.

If, on the other hand, the above 'if' conditional fails to derive any output, the 'then'
directive is skipped and the script moves down to 'else'. All that will show up in my
email on the first of the month will be "No birthdays this month!".

The 'fi' operator simply ends the script.

As you can see, this setup can be used for lots of dates besides birthdays. Holidays,
meetings, filing times, maintenance schedules, test dates, license expiration times,
and, God help you if forget, your WEDDING ANNIVERSARY. :-)

So, read the relevant man pages on commands used in the script so you'll become
more acquainted with not only their usage but also with their flexibility and their
adaptability to different jobs you may need to do. In the meantime, if you just want
to jump in, create your own birthday text file, copy the script, and begin using it in
a cronjob, it should work fine for you and help you not to forget important dates.
My crontab entry looks like this:

01        04        1        *        *        $HOME/birthdays.sh

Back to Tips and Tricks
Home

Delicious Bookmark this on Delicious

No affiliation between this site and the OpenBSD project exists or is implied.

valid-html401.png