Mailing Script


The script to mail out account messages to systems is written in TCL and is actived by cron to run on an hourly basis. It looks for occurrences of files beginning with the prefix SERVER.. The sequence of events within the script is as follows:

  1. Obtain the names of all files that have the prefix SERVER. and set up the names of some workfiles. The actual paths have been removed.

    set filelist [glob -nocomplain {<server file path here>/SERVER.*}] set date [exec date {+%D %H:%M:%S}] puts $date set mailfile <mail file path here> set workfile <work file path here>
  2. For each system for which there exists a file, set the email address for the account creation server on that system. Note that the email addresses have been removed from the listing to protect the innocent.

    foreach outfile $filelist { set server [lindex [split $outfile .] 1] if {[file size $outfile] >= $minsize} { switch -exact $server { Shiraz {set email <email address here>} Merlot {set email <email address here>} Chardonnay {set email <email address here>} Riesling {set email <email address here>} Chablis {set email <email address here>} Cabernet {set email <email address here>} Pilot {set email <email address here>} Modems {set email <email address here>} }
  3. Move the contents of the account file to a work file (so that messages can continue to be added), open the workfile, the mail file, and the relevant log file.

    exec mv $outfile $workfile set wf [open $workfile r] set mf [open $mailfile w] set logfile <log file path> append logfile $server set lf [open $logfile a+]
  4. Build the email mesage and send it.

    puts $mf "To: $email" puts $mf "From: <email address here>" puts $mf "Subject: Student account creation requests" puts $mf "" puts $mf "START" while {[gets $wf line] >= 0} { puts $mf $line puts $lf "[lindex [split $line :] 1] $date" } puts $mf "." close $mf exec /usr/sbin/sendmail -t < $mailfile close $wf close $lf } }

Return to Implementation page...