Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with emailing Timestamp

Status
Not open for further replies.

swabs

IS-IT--Management
Jul 28, 2003
155
US
Hello,
I am trying to set up an automated mailer for testing a product to see if it looses mail. I want the perl script to email me every 30 seconds with the time (ie 10:33:45) in the subject. That way I know if mail has been lost because I will have a timestamp missing. I have a mail script I have used frequently, but when I run it, the timestamp is the same on each mail. Any help would be great

use Net::SMTP;

##################################################################

($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time) ;
#print "$Hour:$Minute:$Second\n";





my $counter =0;
while ($counter <50) {

my $warningEmailMessage .="$Hour:$Minute:$Second";
my $MyToAddress = 'administrator@company.com';
my $MyFromAddress = 'timestamp@company.com';
my $MyCCAddress = 'xxtest3@company.com';
my $MyHost = "mail1";
my $MySite = "company.com";
my $smtp = Net::SMTP->new($MyHost, Hello=>$MySite);
$smtp->mail($MyFromAddress);
$smtp->to($MyToAddress);
$smtp->cc($MyCCAddress);
$smtp->data();
$smtp->datasend("To:$MyToAddress\n");
$smtp->datasend("Subject: $Hour:$Minute:$Second\n");
$smtp->datasend("\n$warningEmailMessage\n");
$smtp->dataend();
$smtp->quit;

print ("\nThe email report was sent successfully.");
sleep 30;
$counter++;

}



 
Your code has the statement that updates the $Hour, $Minute and $Second vars outside the loop - so they only ever get set once.

Try something like this:
Code:
while ($counter <50) {
    my ($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time);
    # Rest of your code
 
rharsh,
thanks very much. Sometimes it is right infront of you and you don't see it.

thanks,
Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top