Can anyone help me to adapt this script to:
(i) give me a reminder not just for the current day, but all upcoming days for the entire month. Maybe the next 15 or 30 days, to allow me to plan ahead. (ii) Pipe this reminder to email to myself.
Thanks! FN
---------- Forwarded message ----------
TWO INTERESTING tiny scripts below, from *Wicked Cool Shell Scripts* (Dave Taylor, No Starch Press, 2004, San Francisco). Both combine to implement a simple calendar program that help you keep track of the events. Extremely useful in the real world of work...
The first script, *addagenda*, enables you to specify either recurring or one-time events. All dates are validated and saved, along with one-line event description, in an *.agenda* file in your home directory.
For its part, the second script, *agenda*, checks all known events, showing which are scheduled for the current date. Useful for remembering birthdays, events, appointments, schedules.
HOW IT WORKS: Weekly, annual and one-time events are accepted. As entries are added to the agenda file, their specified dates are 'normalized' and compressed so that 3 April becomes 3Apr, and Thursday becomes Thu. The *agenda* script checks for events by taking the current date and transforming it into three possible date string formats. It then simply compares each of these date strings to each line in the *.agenda* data file.
This script, writes Dave Taylor, just "scratches the surface of this complex and interesting topic". It would be nice to have a look a few days ahead. This script could be used on a *nix box to send out systemwide reminders. Imagine newspaper reporters getting a reminder of what's on the schedule on that day. Simply have the *agenda* script on each user's machine point to a shared read-only .*agenda* file, and then add a call to the agenda script in each user's *.login* or similar file.
PS: Thanks to Derek Cordeiro for the handholding in making this work!
PPS: Go to http://www.intuitive.com/wicket/ and you'll "find everything you need to continue your journey towards becoming a Shell script Maven", promises author Dave Taylor taylor @ intuitive.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#!/bin/sh
# addagenda - Prompts the user to add a new event for the agenda script.
agendafile="$HOME/.agenda"
isDayName() { # return = 0 if all is well, 1 on error
case $(echo $1 | tr '[[:upper:]]' '[[:lower:]]') in sun*|mon*|tue*|wed*|thu*|fri*|sat*) retval=0 ;; * ) retval=1 ;; esac return $retval }
isMonthName() {
case $(echo $1 | tr '[[:upper:]]' '[[:lower:]]') in jan*|feb*|mar*|apr*|may*|jun*) return 0 ;; jul*|aug*|sep*|oct*|nov*|dec*) return 0 ;; * ) return 1 ;; esac }
normalize() { # Return string with first char uppercase, next two lowercase echo -n $1 | cut -c1 | tr '[[:lower:]]' '[[:upper:]]' echo $1 | cut -c2-3| tr '[[:upper:]]' '[[:lower:]]' }
if [ ! -w $HOME ] ; then echo "$0: cannot write in your history directory ($HOME)" >&2 exit 1 fi
echo "Agenda: The GNU/Linux Reminder Service" echo -n "Date of event (day mon, day month year, or dayname): " read word1 word2 word3 junk
if isDayName $word1 ; then if [ ! -z "$word2" ] ; then echo "Bad dayname format: just specify the day name by itself." >&2 exit 1 fi date="$(normalize $word1)"
else
if [ -z "$word2" ]; then echo "Bad dayname format: unknown day name specified" >&2 exit 1 fi
if [ ! -z "$(echo $word1|sed 's/[[:digit:]]//g')"] ; then echo "Bad date format: please specify day first, by day number" >&2 exit1 fi
if [ "$word1" -lt 1 -o "$word1" -gt 31 ] ; then echo "Bad date format: day number can only be in in range 1-31" >&2 exit 1 fi
if ! isMonthName $word2 ; then echo "Bad date format: unknown month name specified." >&2 exit 1 fi
word2="$(normalize $word2)"
if [ -z "$word3" ] ; then date="$word1$word2" else if [ ! -z "$(echo $word3|sed 's/[[:digit:]]//g')" ] ; then echo "Bad date format: third field should be year." >&2 exit 1 elif [ $word3 -lt 2000 -o $word3 -gt 2500 ] ; then echo "Bad date format: year value should be 2000-2500" >&2 exit 1 fi date="$word1$word2$word3" fi fi
echo -n "One-line description: " read description
# Ready to write to data file
echo "$(echo $date|sed 's/ //g')|$description" >> $agendafile
exit 0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#!/bin/bash
#agenda - Scans through the user's .agenda file to see if there #are any matches for the current or next day.
agendafile="$HOME/.agenda"
checkDate() { #Create the possible default values that'll match today weekday=$1 day=$2 month=$3 year=$4 format1="weekday" format2="$day$month" format3="$day$month$year"
# and step through the file comparing dates....
IFS="|" # the reads will naturally split at the IFS
echo "On the Agenda for today:"
while read date description ; do if [ "$date" = "$format1" -o "$date" = "$format2" -o "$date" = "$format3" ] then echo " $description" fi done < $agendafile
}
if [ ! -e $agendafile ] ; then echo "$0: You don't seem to have an .agenda file. " >&2 echo "To remedy this, please use 'addagenda' to add events" >&2 exit 1 fi
# Now let's get today's date...
eval $(date "+weekday="%a" month="%b" day="%e" year="%G"")
day="$(echo $day|sed 's/ //g')"
checkDate $weekday $day $month $year
exit 0