hmb104 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I'm trying to write a simple script to help me with my network management aspects and I was wondering if it could be written more effectively or is it god enough. What do you think?
use warnings; chomp (my $logsIncDate = `date +"%b %d %H"`); my $TimeStamp = `date +%Y%m%d`; my $currentDate = `date +"%m/%d/%Y %H:%M"`; my $logFile = "/home/log.$TimeStamp"; my $sendemail = 0; my $sendmailPath = "/usr/lib/sendmail myemail\@bng.org\n"; my $subject = "Subject: ";testing... my $from = "From: myemail\@bng.org\n"; my $to = "To: Emyemail\@crf.org\n"; my @err = (); ##### grep through switch logs and if-found send e-mail open SwitchLogs,$logFile or die "Could not open $logFile: $!"; while (<SwitchLogs>) { chomp; my $line = $_; if($line =~ m/$logsIncDate/ && $line =~ m/PM-4-ERR_DISABLE/){ push(@err, "$line\n"); $sendemail = 1; } } close SwitchLogs; if($sendemail == 1){ open(SENDMAIL, "|$sendmailPath") or die "Cannot open $sendmailPath +: $!"; print SENDMAIL $from; print SENDMAIL $subject; print SENDMAIL $to; print SENDMAIL "Content-type: text/plain\n\n"; print SENDMAIL ""; print SENDMAIL "Log messages:\n"; print SENDMAIL "\n"; print SENDMAIL @err; print SENDMAIL "\n"; close(SENDMAIL); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Make my script better
by toolic (Bishop) on Dec 11, 2013 at 20:38 UTC | |
by NetWallah (Canon) on Dec 12, 2013 at 03:51 UTC | |
by toolic (Bishop) on Dec 12, 2013 at 13:16 UTC | |
by hmb104 (Sexton) on Dec 11, 2013 at 20:57 UTC | |
by hmb104 (Sexton) on Dec 11, 2013 at 21:20 UTC | |
by hmb104 (Sexton) on Dec 11, 2013 at 21:04 UTC | |
by toolic (Bishop) on Dec 11, 2013 at 21:06 UTC | |
|
Re: Make my script better
by PerlSufi (Friar) on Dec 11, 2013 at 21:40 UTC |