Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

cron (scheduling) Mail job under Windows

by BigRare (Pilgrim)
on May 05, 2004 at 17:35 UTC ( [id://350934]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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 17: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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://350934]
Approved by Thelonius
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.