I'm having a lot of trouble with this one part my script. I have a script that reads the output of a command (on a Linux system) and does a regexp to sort each field into a variable. It then sends emails out if certain conditions are met (if the email address field exists and if the last field is 'true').
The problem is that I need to store which emails have already been sent out so that users don't get duplicates. I was thinking about using the Storable module to store each email I send out in a text file. I thought the easiest way would be to just store the sequence number of the email ($seq) in the text file, and then check the text file each time to make sure it hasn't already sent that one out yet. Here's the code, minus the Storable part that I can't get working properly.
I was trying to do something like this, but it didn't work...
Thanks a lot if anyone can help me with this, its driving me crazy.
Chris
The problem is that I need to store which emails have already been sent out so that users don't get duplicates. I was thinking about using the Storable module to store each email I send out in a text file. I thought the easiest way would be to just store the sequence number of the email ($seq) in the text file, and then check the text file each time to make sure it hasn't already sent that one out yet. Here's the code, minus the Storable part that I can't get working properly.
Code:
#!/usr/bin/perl -w
use Net::SMTP;
@vfx = `vfxolog -f seq,fem,sub,tnm,tfn,dia,ars,rrs,sbt,csi,nps,don`;
foreach (@vfx) {
$_ =~ /"(.*)","(.*)","(.*)","(.*)","(.*)","(.*)","(.*)","(.*)","(.*)","(.*)","(.*)","(.*)"/;
$seq = $1;
$email = $2;
$subject = $3;
$name = $4;
$tofax = $5;
$dial = $6;
$faxattempt = $7;
$faxresult = $8;
$time = $9;
$csi = $10;
$nps = $11;
$don = $12;
if ($tofax) { substr $tofax, 3, 0, "-"; }
if ($dial) { substr $dial, 3, 0, "-"; }
if ($csi) { $csi =~ s/ /-/g; }
if ($time) {
$year = substr($time,0,4);
$month = substr($time,4,2);
$day = substr($time,6,2);
$hour = substr($time,8,2);
$minute = substr($time,10,2);
$date = $month . '/' . $day . '/' . $year . ' ' . $hour . ':' . $minute;
}
if ($don and $don eq 'true') { $emailsubject = "VSI-Fax Job $seq Completed"; }
if ($email and $don eq 'true') {
$mailserver = '192.0.1.2';
$smtp = Net::SMTP->new($mailserver);
$smtp->mail('VSI-Fax@foo.org');
$smtp->to($email);
$smtp->data();
$smtp->datasend("Subject: $emailsubject\n");
$smtp->datasend("
Sequence Number: $seq
Email address: $email
Subject: $subject
Name: $name
Fax number: $tofax
Dial string: $dial
Fax attempt status: $faxattempt
Fax result status: $faxresult
Submit time: $date
CSI Number: $csi
Number of Pages: $nps
\n");
$smtp->dataend();
$smtp->quit;
}
}
I was trying to do something like this, but it didn't work...
Code:
# at the top of the script...
use Storable;
$file = '/root/faxjobs.txt';
$fax_ref = retrieve($file);
@old = @$fax_ref;
# towards the bottom of the script...
if ($email and $don eq 'true') {
foreach $old (@old) {
if ($seq != $old) {
## then email it like above and store it in a new array
push @new, $seq;
}
}
}
@completed = (@old, @new);
store \@completed, $file;
Thanks a lot if anyone can help me with this, its driving me crazy.
Chris