Hi Paul and all,
Can you check what did I do wrong? I got a tons of mail when I test it
use Time::Local;
$today = timelocal(localtime);
# Full path to sendmail on your system
$mailprog = "|/usr/lib/sendmail -t";
sub date_to_unix {
my $date = @_[0];
my ($time);
my ($mon, $day, $year) = split(/\//, $_[0]);
my ($hour, $min, $sec) = split(/:/, $_[0]);
unless ($day and $mon and $year) { return undef; }
use Time::Local;
eval {
$mon = int($mon) - 1; $day = int($day); $year = int($year) - 1900;
# $time = timelocal($hour, $min, $sec, $day, $mon, $year);
$time = timelocal(0,0,0,$day,$mon,$year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}
open (DATA,"default.db") || die ("Can't Open data File \n");
@data=<DATA>;
close DATA;
foreach $line (@data) {
($ID, $name, $email , $sfc, $startdate, $expiredate, $reason)=split(/\|/,$line);
my $epdate = &date_to_unix($date);
if ($epdate <= ($today - 604800)) { # more than 7 days {
open (Alertmail, "$mailprog") || &cgierr("Can't start mail program");
print Alertmail "To:$email,you.me\@test.com\n";
print Alertmail "From: you.me\@test.com\n";
print Alertmail "Subject: $sfc is expired . \n\n";
print Alertmail "Hi $name,\n\n";
print Alertmail "$sfc is expired more than 7 days. Please remove it out of database or update the expire date";
print Alertmail "-" x 75 . "\n\n";
print Alertmail "Regards,\n\n";
print Alertmail "Tigger, \n\n";
print Alertmail "\n\n";
}
close (Alertmail);
}
I don't have root access to down load lib or mod so that's why it look messy here
Please help me to make it works better.
Thank you for shareing.
Can you check what did I do wrong? I got a tons of mail when I test it
Code:
#!/usr/dist/share/perl use Time::Local;
$today = timelocal(localtime);
# Full path to sendmail on your system
$mailprog = "|/usr/lib/sendmail -t";
sub date_to_unix {
my $date = @_[0];
my ($time);
my ($mon, $day, $year) = split(/\//, $_[0]);
my ($hour, $min, $sec) = split(/:/, $_[0]);
unless ($day and $mon and $year) { return undef; }
use Time::Local;
eval {
$mon = int($mon) - 1; $day = int($day); $year = int($year) - 1900;
# $time = timelocal($hour, $min, $sec, $day, $mon, $year);
$time = timelocal(0,0,0,$day,$mon,$year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}
open (DATA,"default.db") || die ("Can't Open data File \n");
@data=<DATA>;
close DATA;
foreach $line (@data) {
($ID, $name, $email , $sfc, $startdate, $expiredate, $reason)=split(/\|/,$line);
my $epdate = &date_to_unix($date);
if ($epdate <= ($today - 604800)) { # more than 7 days {
open (Alertmail, "$mailprog") || &cgierr("Can't start mail program");
print Alertmail "To:$email,you.me\@test.com\n";
print Alertmail "From: you.me\@test.com\n";
print Alertmail "Subject: $sfc is expired . \n\n";
print Alertmail "Hi $name,\n\n";
print Alertmail "$sfc is expired more than 7 days. Please remove it out of database or update the expire date";
print Alertmail "-" x 75 . "\n\n";
print Alertmail "Regards,\n\n";
print Alertmail "Tigger, \n\n";
print Alertmail "\n\n";
}
close (Alertmail);
}
I don't have root access to down load lib or mod so that's why it look messy here
Please help me to make it works better.
Thank you for shareing.