Okay, I stripped it down to 2 subroutines. Maybe easier to troubleshoot?

The below sends 4 email messages.
If I skip &bakkup; by commenting out, it sends 1 message as expected.
WHY? What's in &bakkup that is interfering with other actions?

Jo




#!/usr/bin/perl -Tw
use strict;
$ENV{'PATH'} = '/bin:/usr/bin';
    delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

my $petFile="/home/devsite/.pets.txt";
my $backupStatus;

use Date::Manip;
my $todayUTS=&UnixDate('today',"%s");



&bakkup;
die unless (
&sendEmail('ad...@dev.xxxxxx.ca','questi...@dev.xxxxxx.ca','Welcome','','hel
lo'));
exit;



sub bakkup {
        my $archive ="/home/devsite/bakTEST/$todayUTS.tar.gz";
        my @filesToBackup = ("$petFile");
        my $failed;
        my $failed2;

        $backupStatus.="Failed to begin backup $! \n" unless defined(my
$pid=open(KIDDO, "-|" ));

        if ($pid) {
                        while (<KIDDO>) {  }
                        close KIDDO;
        }    else {
                        system
("/bin/tar","-czf",$archive,@filesToBackup)==0 or $backupStatus.="Failed
system call\n";
                        my $failed=$?>>8;    #n.b. $_ and $! not useful here
        }

        if ($failed) { $backupStatus.="Failed to backup [tar (pid:$pid)
exited with: $failed ($?)]\n"; }
                else {
                        $backupStatus.="Failed to begin reading $! \n"
unless defined(my $test=open(KID,"-|"));
                        if ($test) {
                                        while (<KID>) {  }
                                        close KID;
                        }     else {
                                        system
("/bin/tar","-tzf",$archive)==0 or $backupStatus.="Failed system call\n";
                                        my $failed2=$?>>8;
                        }

                        if ($failed2) { $backupStatus.="Failed to test
backup:tar(pid:$test)exited with:[$failed2]($?)"; }
                                 else { $backupStatus.="Successfully backed
up files"; }
        }
}


sub sendEmail {
        my ($efrom, $eto, $esub, $ehdr, $ebody) = @_;
        open (MAIL, "|/usr/lib/sendmail -t -i");
        print MAIL <<EOF;
From: $efrom
To: $eto
Subject: $esub
$ehdr

$ebody
EOF
        close (MAIL);
return 1;
}


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to