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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.