Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

I can't get cron to work on cygwin...

by cecil36 (Pilgrim)
on Jun 12, 2002 at 14:12 UTC ( #173832=perlquestion: print w/replies, xml ) Need Help??
cecil36 has asked for the wisdom of the Perl Monks concerning the following question: I'm thinking about writing a script in perl that will call another perl script every hour. What tools or modules would I need to get?

Replies are listed 'Best First'.
Re: I can't get cron to work on cygwin...
by vladb (Vicar) on Jun 12, 2002 at 14:16 UTC
    If you simply need to invoke a script every once in a while (say, 1 hour), you can pretty much get by without the aid of special modules. Simply, have a main loop in your script, inside of which you'll spawn off a process and sleep for 1 hour and then repeat this cycle all over again.
    my $script = ''; my $sleep_time = 60*60; # sleep for 1 hour. while (1) { system(""); sleep($sleep_time); }

    UPDATE: However, for complex scheduling, I suggest you take a look at the Schedule-Cron module. So, your script might look as following:
    use Schedule::Cron; sub run_scripts { system(""); } # Create new object with default dispatcher my $cron = new Schedule::Cron(); # Add dynamically crontab entry # invoke run_scripts() every 0 minute past # each hour. $cron->add_entry("0 * * * Mon-Fri", \&run_scripts); # Run scheduler $cron->run(detach=>1);

    #%  xxxxxx   xx-+  xx    xxx xx  xx       xx  xx   xxx   xxxxx+ xx  xx xxxx xxxxx  ......+
    #x xxxxvxxx xx  xx xv   xxxx x+ %+  ===== xx  xx  xx xx  x+  =x xx xx  xx   xx xx ...+
    #x xx xx xx xx  xx xx  xx xx xxx+         xxxxxx xx   +x xx     xx+x-  xxxx xxxx ........+
    #% xx xx xx xx  xx xx xx  x+ xx xx  =+=== xx  xx xxxx-xx xx  =x +x xx  xx   xx xx ...+
    #% xx xx xx  -+x+  xxx+   xx xx  xx       xx  xx x+   xx xxx+xx xx  xx xxxx xx  xx ....+~
    for(split/$~/){s,[ $/],,g;/(.)$/;$l=$-[0];/(.)/||next;$_=chr$-+$l;$".=($1=~/$^/)?" \u$_":$_;}print$";
Re: I can't get cron to work on cygwin...
by perrin (Chancellor) on Jun 12, 2002 at 14:25 UTC
    The "Scheduled Tasks" feature of Windows (at least Win2K) works just fine for this. I've been using it for months with no trouble.
      I second that. I use cygwin all the time but for something like this, I would use Scheduled Tasks (you can find it in the Control Panel on Win2K) or the scheduler service on NT. I currently use Scheduled Tasks to run a Perl script daily and it works great.
Re: I can't get cron to work on cygwin...
by Joost (Canon) on Jun 12, 2002 at 14:20 UTC
    I remember hearing something about an at command on windows, so maybe you can look at that.


    while (1) { system("some command") and die "Error running command: $?"; sleep 60*60; }
    Should at least try to do the job.
    -- Joost downtime n. The period during which a system is error-free and immune from user input.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://173832]
[hippo]: I had a low-paid job about 20 years ago and seriously considered going down to a 3-day week. Would have worked 60% of the time for about 80% of the cash.
[Corion]: ambrus: Well, I pay rent, but don't own a house with variable/ unforeseeable costs
[hippo]: The thesholds/benefits balance at the time was nuts.
[hippo]: But that doesn't last because, you know ... politicians. :(
[Corion]: hippo: Yeah, if you still get enough money to get by and don't have expensive hobbies or other fixed costs that can work out well
[ambrus]: ah good. I pay only rent too. but that still costs significant money.
[Corion]: ambrus: Yes, but that is already budgeted for

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2017-09-21 15:19 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (249 votes). Check out past polls.