#!/bin/sh # creates the allmsg shell script to send messages to a class # usage: makeallmsg [-f ] # Has one parm $1: the file containing student names & email addresses # one per line. Each line is expected to be of the form # login_id email_address Name # turing aturing@erols.com Alan Mathison Turing # Everything after the email address is treated as the name # creates a shell script in the current directory # default name is 'allmsg' unless name is given through -f flag # Bill Bynum # August 1998 pgmname=`basename $0` sname=allmsg usage(){ echo 'Usage: '$pgmname' [ -f scriptname ] name_list_file' echo " 'scriptname' is the name of the script to be produced" echo " default is \"$sname\"" echo " 'name_list_file' is a file containing student user ids, email addresses echo " and names, one student per line. Each line is expected to be of echo " the form" echo " user id email address name" echo " turing aturing@erols.com Alan Mathison Turing" echo " Everything after the email address is treated as a part of the name" } case $# in 0) usage exit;; esac while true do case $1 in -f) sname=$2 shift shift;; -*) usage exit;; *) break;; esac done case $1 in "") usage exit;; esac if (test ! -f $1) then echo "The file \"$1\" of names does not exist!" exit fi if (test -f $sname) then rm -f $sname fi echo '#!/bin/sh' > $sname echo "# Created by `basename $0` from $1 `date`" >> $sname echo 'BYNUMBIN=/home/f85/bynum/bin' >> $sname echo 'sysbin=/bin:/usr/bin:/usr/local/bin:/usr/lib' >> $sname echo 'otherbin=$HOME/bin:$BYNUMBIN:$BYNUMBIN/i586' >> $sname echo 'PATH=$sysbin:$otherbin:.' >> $sname echo 'usage(){' >> $sname echo ' echo "Usage: $pgmname [ -d ] msg_fname subject"' >>$sname echo ' echo " \"msg_fname\" and \"subject\" are BOTH REQUIRED"' >>$sname echo ' echo " -d debug (show message, but don'\''t send it)"' >>$sname echo '}' >> $sname echo 'pgmname=`basename $0`' >> $sname echo 'case $# in' >> $sname echo '0|1) usage' >> $sname echo ' exit;;' >> $sname echo 'esac' >> $sname echo 'while true' >> $sname echo 'do' >> $sname echo ' case $1 in' >> $sname echo ' -d) debug="-d"' >> $sname echo ' shift;;' >> $sname echo ' -*) echo "Unknown option \"$1\""' >> $sname echo ' usage' >>$sname echo ' exit;;' >> $sname echo ' *) break;;' >> $sname echo ' esac' >> $sname echo 'done' >> $sname echo 'case $# in' >> $sname echo '0|1) usage' >> $sname echo ' exit;;' >> $sname echo 'esac' >> $sname echo 'if (test ! -f $1) then' >> $sname echo ' echo "The message file \"$1\" does not exist!"' >> $sname echo ' exit' >> $sname echo 'fi' >> $sname awk ' $1 ~ /#/ || $1 ~ /^$/ $1 !~ /#/ && $1 !~ /^$/ { printf("sendmsg '\$'debug \"") printf("%s",$3); for (i = 4;i <= NF; i++) printf(" %s",$i) printf("\" %s $1 \"$2\"\n",$2) } ' $1 >> $sname echo 'echo all messages sent' >> $sname echo Make $sname executable ... chmod 700 $sname # # $Id: makeallmsg,v 1.11 2005/09/20 13:22:41 bynum Exp $ #