seigniory has asked for the wisdom of the Perl Monks concerning the following question:
Why won't this program work when scheduled? All I get is a blank email, so I know the script is trying to run. And yes, I know it's rather ugly and I should really use the Net:SMTP object, but I'm not trying to be too pretty right now... build the walls and roof first, put the furniture in after it's watertight. Thanks in advance -- Matt########################################################### # IIS Log File Archiver # Resurses through directories and zips all files, # removes the old file if successful, then emails a # detailed log file to the specified email address. ########################################################### $directory = 'K:\'; $zipApp = 'D:\IISArchive\wzzip.exe'; $logFile = ''; $SMTPServer = '10.0.1.2'; $mailTo = 'me@me.com'; $reportSubject = 'Daily IISArchive Report'; ########################################################### use Socket; $|++; &recurseDirectory($directory); &emailLogFile(); exit; ########################################################### sub recurseDirectory { my $zipApp = 'D:\IISArchive\wzzip.exe'; my $thisDirectory = $_[0] . "\\"; opendir (THISDIR, $thisDirectory); my @theseContents = readdir (THISDIR); closedir (THISDIR); foreach my $item (@theseContents) { if (!($item =~ /\.zip$/)) { if (!($item =~ /^\./)) { my $temp = $thisDirectory.$item; if (-d $temp) { $::logFile .= "\n_____________________\n$item\ +n"; &recurseDirectory($temp); } else { my $tempZipped = $temp; $tempZipped =~ s/\.log/\.zip/g; if (¬TodaysLogFile($item)) { $::logFile .= "$::zipApp \"$tempZipped\" \ +"$temp\"\n"; my $result = `$::zipApp -m \"$tempZipped\" + \"$temp\"\n`; $::logFile .= $result."\n"; if ($result =~ /Unable to erase the file:/ +) { unlink($tempZipped); } } else { $::logFile .= " --> Skipping today's log f +ile, $item\n"; } } } } } } ########################################################### sub notTodaysLogFile { my @times = localtime(time); $times[5] = $times[5] - 100; if ($times[5] < 10) { $times[5] = "0".$times[5]; } $times[4]++; if ($times[4] < 10) { $times[4] = "0".$times[4]; } if ($times[3] < 10) { $times[3] = "0".$times[3]; } if ($_[0] =~ /$times[5]$times[4]$times[3]\.log/) { return 0; } else { return 1; } } ########################################################### sub emailLogFile { my $smtp_server = $::SMTPServer; my $pop_server = $smtp_server; my $to = $::mailTo; my $subject = $::reportSubject; my $message = $::logFile; my $proto = getprotobyname('tcp'); socket(SOCK, AF_INET, SOCK_STREAM, $proto); my $iaddr = gethostbyname($smtp_server); my $port = getservbyname('smtp', 'tcp'); my $sin = sockaddr_in($port, $iaddr); connect(SOCK, $sin); my $err = ''; send SOCK, "HELO localhost\r\n", 0; recv SOCK, $junk, 512, 0; if ($junk =~ /^5/) {$err = "true";} send SOCK, "mail from: <IISArchive\@webloyalty.com>\r\n", 0; recv SOCK, $poo, 512, 0; if ($poo =~ /^5/) {$err = "true";} send SOCK, "RCPT To:<$to>\r\n", 0; recv SOCK, $poo, 512, 0; if ($poo =~ /^5/) {$err = "true";} send SOCK, "DATA\r\n", 0; recv SOCK, $poo, 512, 0; if ($poo =~ /^5/) {$err = "true";} send SOCK, "From: IISArchive\@webloyalty.com\r\n", 0; send SOCK, "Date: ".localtime()."\r\n", 0; send SOCK, "To: $to\r\n", 0; send SOCK, "Subject: $subject\r\n", 0; send SOCK, "\r\n$message\r\n.\r\n", 0; recv SOCK, $poo, 512, 0; if ($poo =~ /^5/) {$err = "Yes";} send SOCK, "QUIT\r\n", 0; recv SOCK, $poo, 512, 0; if ($poo =~ /^5/) {$err = "Yes";} close SOCK; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re: Windows Scheduler Issues
by tye (Sage) on Mar 30, 2001 at 03:32 UTC | |
by seigniory (Sexton) on Mar 30, 2001 at 03:37 UTC | |
by tye (Sage) on Mar 30, 2001 at 03:47 UTC | |
|
Re: Windows Scheduler Issues
by wardk (Deacon) on Mar 30, 2001 at 05:26 UTC | |
|
Re: Windows Scheduler Issues
by myocom (Deacon) on Mar 30, 2001 at 04:15 UTC | |
|
(jcwren) Re: Windows Scheduler Issues
by jcwren (Prior) on Mar 30, 2001 at 19:18 UTC | |
by seigniory (Sexton) on Mar 30, 2001 at 21:28 UTC | |
by tye (Sage) on Mar 31, 2001 at 00:40 UTC | |
|
Re: Windows Scheduler Issues
by c-era (Curate) on Mar 30, 2001 at 18:57 UTC | |
|
Re: Windows Scheduler Issues
by jorg (Friar) on Mar 30, 2001 at 19:01 UTC |