#!/usr/bin/perl -w use English; use MIME::Lite; use Cwd; sub execute_cmd { my($this_cmd) = pop(@_); my($pid); printf "Executing '$cmd' \n"; $pid = open (LAST,"$cmd |"); while () { print $_; } close(LAST); } #$_=`/usr/ucb/whoami`; #chop; #$person = $_; $person = $ENV{USER}; ## Change these variables $simdir = "sim2"; $assignment="VLSI2_sim2"; $target_dir = "/home/reese/vlsi_dev/sims/$person"; @files = ("$simdir/report.pdf"); # for file check ##### $tarname="tmp_submit"; $uuname = $tarname . "\.uu"; $maxsize = 1000000; $fail = 0; if (!-e $simdir) { printf "Expecting a directory named $simdir\n. File not submitted.\n"; exit(1); } foreach $file (@files) { printf "Checking existence of: $file \n"; if (!(-e $file)) { printf STDERR "Can't find file: $file\n"; $fail = 1; } } if ($fail) { printf STDERR "File Existence check failed, project not submitted \n"; exit(-1); } printf STDERR "Creating uuencoded tar file...\n"; $cmd = "tar cf - $simdir | compress > $tarname.tar.Z"; &execute_cmd($cmd); if (!(-e "$tarname.tar.Z")) { printf STDERR "Tar file creation failed. Internal error, send email to reese\@erc.msstate.edu \n"; printf STDERR "Homework not submitted.\n"; exit(-1); } @fstats = stat("$tarname.tar.Z"); $fsize = $fstats[7]; if ($fsize > $maxsize) { print STDERR "Your compressed TAR file ($tarname.tar.Z) submission is too big (> $maxsize bytes) \n"; print STDERR "Make sure only ESSENTIAL files are in the $simdir directory. \n"; print STDERR "Homework not submitted.\n"; exit(-1); } printf STDERR "Mailing compressed tar file...\n"; #$cmd = "mailx -s $assignment reese\@erc.msstate.edu $person < $uuname"; $msg = MIME::Lite->new(From => "$ENV{USER}", To => "reese\@erc.msstate.edu", Cc => "$ENV{USER}", Subject => "$assignment", Type => 'multipart/mixed'); $msg->attach(Type => 'TEXT', Data => "TARGET_FILE $target_dir/$tarname.tar.Z\n\n"); $msg->attach(Type => 'Application/PDF', Encoding => 'base64', Path => "$tarname.tar.Z"); $msg->send || warn "ERROR: Report mailing to reese\@erc.msstate.edu failed. Report not sent.\n"; &execute_cmd($cmd); `rm -f $tarname.tar.Z`; printf STDERR "Project submitted. Mailed to both reese\@erc.msstate.edu and $person\n";