in reply to Make my script better
use warnings; use strict; use POSIX qw(strftime); my $logsIncDate = strftime('%b %d %H', localtime); my $TimeStamp = strftime('%Y%m%d' , localtime); my $logFile = "/home/log.$TimeStamp"; my $sendmailPath = '/usr/lib/sendmail myemail@bng.org'; my $subject = 'Subject: Emyemail@crf.org'; my $from = 'From: myemail@bng.org'; ##### grep through switch logs and if-found send e-mail my @err; open SwitchLogs, '<', $logFile or die "Could not open $logFile: $!"; while (<SwitchLogs>) { push @err, $_ if /$logsIncDate/ && /PM-4-ERR_DISABLE/; } close SwitchLogs; if (@err) { open(SENDMAIL, "|$sendmailPath") or die "Cannot open $sendmailPath +: $!"; print SENDMAIL <<EOF; $from $subject $to Content-type: text/plain Log messages: @err; EOF close(SENDMAIL); }
Note: you don't set $to
Update: due to NetWallah
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Make my script better
by NetWallah (Canon) on Dec 12, 2013 at 03:51 UTC | |
by toolic (Bishop) on Dec 12, 2013 at 13:16 UTC | |
|
Re^2: Make my script better
by hmb104 (Sexton) on Dec 11, 2013 at 20:57 UTC | |
|
Re^2: Make my script better
by hmb104 (Sexton) on Dec 11, 2013 at 21:20 UTC | |
|
Re^2: Make my script better
by hmb104 (Sexton) on Dec 11, 2013 at 21:04 UTC | |
by toolic (Bishop) on Dec 11, 2013 at 21:06 UTC |