BigRare has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a script to test a handful of mail accounts on our mailserver. This script needs to run automatically every half hour on a Windows machine, unfortunately, I don't have access to cron. My questions are: Is the script below the way to do this? and; Can anyone recommend a better method?
#!/usr/bin/perl -w use strict; use MIME::Lite; use Date::Calc qw(Today_and_Now Date_to_Text_Long); my $gmt; my $sleeptimer; my ($year,$month,$day, $hour,$min,$sec) = Today_and_Now([$gmt]); my $sig = "\n\nHere is my sig"; my $time = sprintf("%s, %s:%s:%s", Date_to_Text_Long($year,$month,$day), $hour, $min, $sec ); my $msg = MIME::Lite->new( From =>'test@account.com', To =>'test1@account.com', Cc =>'test2@account.com, test3@account.com', Bcc =>'test@account.com', Subject =>'This is a test message', Data =>"This message was sent from my script:\n\n +$time$sig" ); if ($min > 30) { $sleeptimer = 60 - $min; $sleeptimer = $sleeptimer * 60; } elsif ($min < 30) { $sleeptimer = 30 - $min; $sleeptimer = $sleeptimer * 60; } else { $sleeptimer = 1800; } if ($sleeptimer ne 1800) { sleep $sleeptimer; } do {$msg-> send('smtp', "mail.server.com", Timeout=>60); sleep 1800; redo; }
Edited: Retitled

Replies are listed 'Best First'.
Re: Mail Test Script
by NetWallah (Canon) on May 05, 2004 at 21:47 UTC
    Depending on your flavour of Windows, you can use either the "AT" command, or the windows scheduler (Scheduled tasks under control panel) to get cron-like functionality.

    I would take out all the SLEEP commands, and schedule the task to run periodically, using the scheduler.

    If you really want to be a perl-timed control freak, you can do that by making your program into a service. See documentation for SRVANY in the Windows Resource Kit.

    Offense, like beauty, is in the eye of the beholder, and a fantasy.
    By guaranteeing freedom of expression, the First Amendment also guarntees offense.
        Thanks for the link. The main problem with using the Windows Task Schedular though is that it pops up in a window every time it runs.