in reply to Make my script better

For some value of "better" (untested):
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
    Shouldn't that be:
    print SENDMAIL <<EOF;
    ?

                 When in doubt, mumble; when in trouble, delegate; when in charge, ponder. -- James H. Boren

      Of course. Like I said: untested. Updated. Thanks.
Re^2: Make my script better
by hmb104 (Sexton) on Dec 11, 2013 at 20:57 UTC

    Thanks toolic for the tips. I like the idea of using the localtime because I do run the scripts in multiple timezones.

Re^2: Make my script better
by hmb104 (Sexton) on Dec 11, 2013 at 21:20 UTC

    I do not have specific questions. I did try to use the terminator for the print statement before and I wasn't abe to use sendmail with it.

    Thanks for the localtime hint. I fixed my script accordingly.

Re^2: Make my script better
by hmb104 (Sexton) on Dec 11, 2013 at 21:04 UTC

    Don't we need to define the string terminator before using it?

      I don't understand your question. Please elaborate using code examples.