#======================================================================= # # BuffSched - Scans through the user's .schedule file to see if there # are any matches for the current and set number of days. # # Author: Scott Buffington # # Change History: # Scott Buffington - 10/30/2006 - Created. # Scott Buffington - 11/26/2006 - Added three month calendar for Linux # and Mac. # Scott Buffington - 11/27/2006 - Added OS check. # Scott Buffington - 12/06/2006 - Cosmetic update. # Scott Buffington - 02/17/2007 - Added Solaris 10 Support, comments # and code cleanup as well. # Scott Buffington - 08/27/2007 - Added AIX Support. # Scott Buffington - 01/15/2008 - Added ability to pull schedule of # future or past dates. # # License: GPL, http://www.gnu.org/copyleft/gpl.html # # Version: 1.9.2 # #======================================================================== #======================================================================== # These should be the only variables that you might want to change. #======================================================================== NUMDAYS=7 schedulefile="$HOME/.schedule" #======================================================================== # Usage statement check. #======================================================================== USAGE="Usage: `basename $0` [dd/mm/ccyy] example: `basename $0` `basename $0` 31/10/2008" if [ $# -gt 1 ] then clear echo "$USAGE" exit 1 fi #======================================================================== # tput commands to control highlighting # Note: some terminals do not support all tput options #======================================================================== RVR=`tput smso` # reverse END_RVR=`tput rmso` # end reverse BLNK=`tput blink` # blink UNDER=`tput smul` # underline END_UNDER=`tput rmul` # underline CLEAR=`tput clear` # clear screen BELL=`tput bel` # bell sound BOLD=`tput bold` # bold DIM=`tput dim` # dim INVIS=`tput invis` # invisible END=`tput sgr0` # turn off dim, blink, bold, dim, invisible #======================================================================== # Operating System Check. #======================================================================== case `uname` in SunOS) export OSTYPE=HPSun export AWKPATH="/usr/xpg4/bin" export LOGONNAME=`finger $LOGNAME |awk 'NR==1 {print $7 " " $8;exit}'` ;; AIX) export OSTYPE=AIX export AWKPATH="/usr/bin" export LOGONNAME=`finger $LOGNAME |awk 'NR==1 {print $7 " " $8;exit}'` ;; HP-UX) export OSTYPE=HPSun export AWKPATH="/usr/bin" export LOGONNAME=`finger $LOGNAME |awk 'NR==1 {print $9 " " $10;exit}'` ;; Darwin) export OSTYPE=OSX export AWKPATH="/usr/bin" export LOGONNAME=`finger $LOGNAME |awk 'NR==1 {print $4 " " $5;exit}'` ;; Linux) export OSTYPE=Linux export AWKPATH="/usr/bin" export LOGONNAME=`finger $LOGNAME |awk 'NR==1 {print $4 " " $5;exit}'` ;; *) clear echo "This utility has not been tested on this Operating System yet." echo "Valid systems are AIX, HP-UX, Solaris 10, Mac OS X, and Linux. If you want" echo "BuffSched, you can help make BuffSched work on your system. Altering" echo "the first case statement can get BuffSched working. For assistance," echo "contact Scott. The goal is to have BuffSched work on all Unices." exit 1 ;; esac #======================================================================== # This is the function that prints your schedule. #======================================================================== checkDate() { weekday=$1 day=$2 month=$3 year=$4 format1="$weekday" format2="$day$month" format3="$day$month$year" export IFS=" | " # The reads will naturally split at IFS if [ $cnt -eq 1 ] && [ -z "$backFuture" ] then echo "${BOLD}On the Schedule for today:${END}" else case $weekday in Sun) weekdayfull=Sunday;; Mon) weekdayfull=Monday;; Tue) weekdayfull=Tuesday;; Wed) weekdayfull=Wednesday;; Thu) weekdayfull=Thursday;; Fri) weekdayfull=Friday;; Sat) weekdayfull=Saturday;; esac echo "${BOLD}On the Schedule for $weekdayfull, $month $day, $year:${END}" fi while read date description do if [ "$date" = "$format1" -o "$date" = "$format2" -o "$date" = "$format3" ] then if [ $cnt -eq 1 ] then echo $description |grep -i birthday >/dev/null if [ $? -eq 0 ] then description=`echo $description | sed 's/^[ ]*//;s/\|//g'` echo " ${BLNK}$description${END}" data="TRUE" else description=`echo $description | sed 's/^[ ]*//;s/\|//g'` echo " $description" data="TRUE" fi else description=`echo $description | sed 's/^[ ]*//;s/\|//g'` echo " $description" data="TRUE" fi fi done < $schedulefile if [ -z "$data" ] then echo " Nothing scheduled for this date." fi data="" } #======================================================================== # Function to define weekday. #======================================================================== weekDayNum() { case $weekday in 1) weekday=Mon;; 2) weekday=Tue;; 3) weekday=Wed;; 4) weekday=Thu;; 5) weekday=Fri;; 6) weekday=Sat;; 0) weekday=Sun;; *) echo Notify Scott;; esac } #======================================================================== # Function to calculate the next weekday. #======================================================================== weekDay() { case $weekday in Sun) weekday=Mon;; Mon) weekday=Tue;; Tue) weekday=Wed;; Wed) weekday=Thu;; Thu) weekday=Fri;; Fri) weekday=Sat;; Sat) weekday=Sun;; *) echo Notify Scott;; esac } #======================================================================== # Function to calculate the month name. #======================================================================== monthNum() { case $monthcal in 1) month=Jan;; 2) month=Feb;; 3) month=Mar;; 4) month=Apr;; 5) month=May;; 6) month=Jun;; 7) month=Jul;; 8) month=Aug;; 9) month=Sep;; 10) month=Oct;; 11) month=Nov;; 12) month=Dec;; *) month=Jan;; esac } #======================================================================== # Function to calculate the day of the week given a date. #======================================================================== dayOfWeek() { _y=$3 _m=$2 _d=$1 case $_m in 1|5) _t=0 ;; 2|6) _t=3 ;; 3|11) _t=2 ;; 4|7) _t=5 ;; 8) _t=1 ;; 9|12) _t=4 ;; 10) _t=6 ;; esac [ $_m -lt 3 ] && _y=$(( $_y - 1 )) _DAYOFWEEK=$(( ($_y + $_y/4 - $_y/100 + $_y/400 + $_t + $_d) % 7 )) weekday=`echo $_DAYOFWEEK` } #======================================================================== # Function to calculate the month number and the year. #======================================================================== getDate() { # syntax: getDate monthGap themonth=$(($monthcal+$1)) theyear=$yearcal if [ $themonth -gt 12 ] then themonth=$(($themonth-12)) theyear=$(($theyear+1)) fi if [ $themonth -lt 1 ] then themonth=$((12-$themonth)) theyear=$(($theyear-1)) fi echo $themonth " " $theyear } #======================================================================== # Function that marks the correct date with brackets on the calendar. #======================================================================== MarkToday() { $AWKPATH/awk -v cday=$currDay '{ fill=(int(cday)>9?"":" "); a=$0; sub(" "fill int(cday)" ","["fill int(cday)"]",a); print a }' } #======================================================================== # Function that displays the calendars at the top of the screen. #======================================================================== doCalUS() { cal $(getDate -1) echo cal $monthcal $yearcal | awk '{ print " " $0 " " }' | MarkToday echo cal $(getDate 1) } #======================================================================== # Main program processing. #======================================================================== #======================================================================== # We get the current date and time for various features. Check for date # argument to check your schedule in the past or future. #======================================================================== if [ $# -lt 1 ] ; then eval $(date "+weekday=\"%a\" month=\"%b\" monthcal=\"%m\" currDay=\"%e\" yearcal=\"%Y\"") currDay=`echo $currDay | sed 's/ //g'` lastday="$(cal $monthcal $yearcal |grep -v "^$" |tail -2 |awk '{print $NF}' |tail -1)" else monthcal=`echo $1 |awk -F/ '{print $2}'` currDay=`echo $1 |awk -F/ '{print $1}'` yearcal=`echo $1 |awk -F/ '{print $3}'` monthcal="$(echo $monthcal | sed 's/0*//')" currDay="$(echo $currDay | sed 's/0*//')" if [ "$monthcal" -lt 1 -o "$monthcal" -gt 12 ] then echo "Bad date format: month value should be 1-12" echo "$USAGE" exit 1 elif [ "$yearcal" -lt 2006 -o "$yearcal" -gt 2500 ] then echo "Bad date format: year value should be 2006-2500" echo "$USAGE" exit 1 elif [ "$currDay" -lt 1 -o "$currDay" -gt 31 ] then echo "Bad date format: day value should be 1-31" echo "$USAGE" exit 1 fi yeaR=`echo $yearcal |sed 's/^..0*//'` century=`echo $yearcal |sed 's/..$//'` monthNum dayOfWeek $currDay $monthcal $yeaR $century weekDayNum lastday="$(cal $monthcal $yearcal |grep -v "^$" |tail -2 |awk '{print $NF}' |tail -1)" backFuture="BF" fi Hour=`date +%H` #======================================================================== # Let's start the application. #======================================================================== clear echo " ${RVR}BuffSched: The Unix Reminder Service${END_RVR}" case $OSTYPE in HPSun) doCalUS | pr -3 -t -i100 |tbl ;; AIX) cal $monthcal $yearcal | sed "s/ ${currDay} / ${RVR}${currDay}${END_RVR} /" ;; *) doCalUS | pr -3 -t -i100 | colrm 22 24 | colrm 44 44 ;; esac if [ ! -r "$schedulefile" ] ; then echo "$0: You do not seem to have a .schedule file. " >&2 echo "To remedy this, please use 'buffadd' to add events" >&2 exit 1 fi case $Hour in 0?|1[01]) echo Good Morning ${DIM}${LOGONNAME}${END} ;; 1[2-7] ) echo Good Afternoon $LOGONNAME ;; * ) echo Good Evening $LOGONNAME ;; esac currDay="$(echo $currDay|sed 's/ //g')" cnt=0; until [ $cnt -ge $NUMDAYS ] do cnt="$(echo "$cnt + 1" |bc)" checkDate $weekday $currDay $month $yearcal lastday="$(echo $lastday|sed 's/ //g')" if [ "$currDay" -eq "$lastday" ] then monthcal="$(echo "$monthcal + 1" |bc)" monthNum weekDay currDay=1 if [ "$month" = Jan ] then yearcal="$(echo "$yearcal + 1" |bc)" fi else currDay="$(echo "$currDay + 1" |bc)" weekDay fi done exit