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:
- 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.*}]
set date [exec date {+%D %H:%M:%S}]
puts $date
set mailfile
set workfile
- 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 }
Merlot {set email }
Chardonnay {set email }
Riesling {set email }
Chablis {set email }
Cabernet {set email }
Pilot {set email }
Modems {set email }
}
- 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
append logfile $server
set lf [open $logfile a+]
- Build the email mesage and send it.
puts $mf "To: $email"
puts $mf "From: "
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...