mardi 21 juin 2016

Perl script if else statement not sending mailx

I have a script that checks a .txt file. the .txt file only has one number (0 or 1) if the number = 0 it should send out an email alert. if the number = 1 do nothing. For some reason my email is not being sent. any help would be appreciated.

code below:

use warnings;
use strict;

my $file = '/users/tneal01/SPOOL/output.txt';
my $mark = 0;


my $cont = do {
    open my $fh, '<', $file  or die "Can't open $file -- $!";
    local $/;
    <$fh>;
};

# Pull the first number
my ($num) = $cont =~ /^(\d+)/;

if ($num = $mark)
{
    my $body = "status $num has been recorded ";
    my $cmd_email = "echo $body | " .
        "mailx -s \"error occurring\" tneal01\@gmail.com";
    system($cmd_email) == 0  or die "Error sending email -- $!";
}

Aucun commentaire:

Enregistrer un commentaire