#!/bin/sh # mailgrades # Bourne shell script to email grades to a student. Used by # allgrade shell script. Expects to find an ASCII file # $GRADEFILE (default "grades.sc.asc") in the current directory # that contains the student's grades # Bill Bynum # August 1998 # PAUSE=2 sysbin=/usr/local/bin:/usr/local/gnu/bin:/bin:/usr/bin:/usr/lib otherbin=$HOME/bin:/home/f85/bynum/bin PATH=$sysbin:$otherbin:. case $GRADEFILE in "") GRADEFILE=grades.sc.asc;; esac pgmname=`basename $0` usage() { echo "Usage: $pgmname [options] \"person name\" mailaddr class_label" echo " \"person name\" quoted full name of the recipient" echo " mailaddr email address of the recipient" echo " class_label descriptive title of the class" echo "Options" echo " -d debug only, don't send the grade email" echo " -m msg_file include msg_file at the top of the grade email" echo "Script expects to find an ASCII file called $GRADEFILE where grades" echo " are stored. You can change the name of this file to anything" echo " you want by setting the environment variable GRADEFILE" } listing= while true do case $1 in "-d") debug=T shift;; "-m") if (test ! -f $2) then echo "Message file \"$2\" does not exist!" usage exit fi msgfname=$2 shift shift;; "-l") listing=yes shift;; *) break;; esac done case $1 in "") echo "Person's name is required!" usage exit;; esac case $2 in "") echo "Person's e-mail address is required!" usage exit;; esac case $3 in "") echo "Class label is required!" usage exit;; esac case $listing in yes) echo Adding grade listing for $1 echo " Latest grades for $1 in $3" > tmsg ;; *) echo Sending grade mail to $1 echo "To: $2" > tmsg echo "Subject: Latest grades for $1 in $3" >> tmsg ;; esac echo "" >> tmsg date >> tmsg echo "" >> tmsg case $msgfname in "") ;; *) echo "=============================================" >> tmsg cat $msgfname >> tmsg echo "=============================================" >> tmsg echo "" >> tmsg;; esac head -4 $GRADEFILE >> tmsg grep "$1" $GRADEFILE>> tmsg grep "[Cc]lass [Aa]verages" $GRADEFILE >> tmsg echo "" echo "" echo 'Message to be sent (or listing to be added):' cat ./tmsg case $listing in yes) cat ./tmsg >> listing.out echo "" >> listing.out echo "" >> listing.out ;; *) if (test "$debug" = "T") then echo "No message sent (just debugging)" else # echo "pause $PAUSE seconds for Postfix" # sleep $PAUSE sendmail $2 < ./tmsg fi ;; esac rm -f ./tmsg # # $Id: mailgrades,v 1.5 2005/09/19 14:35:34 bynum Exp bynum $ #