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); }
In reply to Make my script better by hmb104
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |