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

Dear perlmonks: I have a webpage which is updated every hour. I want to use a perl program to download this webpage. So I need to let the program run once every hour. How can I let the program automatically do that? I am using a windows system. Thank you in advance...
  • Comment on how can I automatically run the program every hour?

Replies are listed 'Best First'.
Re: how can I automatically run the program every hour?
by Vautrin (Hermit) on Feb 10, 2004 at 18:12 UTC
    If you're looking to create a daemon (i.e. once you start up your script it runs in the background waiting every hour) you could use sleep to have the script wait 60 * 60 seconds (1 hour) and download the web page again (in an infinite loop, or provided some conditions are met, or whatever you wanted to do)

    Want to support the EFF and FSF buy buying cool stuff? Click here.
Re: how can I automatically run the program every hour?
by arden (Curate) on Feb 10, 2004 at 18:30 UTC
    Although this has nothing to do with perl . . .

    If you are on Windows NT, 2000, or XP, you can use the AT command. From a command prompt, type AT /? to get the usage. By using AT you don't actually have to be logged in, the computer just needs to be running.

    If you are using Windows 95, 98, or Me (or if you don't have access to the AT command due to security restrictions on your computer), you will have to set a sleep timer of approximately 3600 seconds in a loop in your script.

    The biggest problem with doing the sleep method is that you are putting your script into an endless loop. You can set up a condition which will exit the loop if you want, or you can just allow windows to terminate the process when the system reboots (or logs off).

      On Windows you should also be able to use:
      Start - Programs - Accessories - System Tools - Scheduled Tasks
      HTH.
        briefly explain it please

      AT is simple to use. Use military time:
      at 14:45 "perl program.pl"

      It is easier to set them up with the Task Scheduler in windows, but you can still view the schedule by typing "at" at a command line. (Even via telnet.)

Re: how can I automatically run the program every hour?
by Abigail-II (Bishop) on Feb 10, 2004 at 18:05 UTC
    On Unix, you'd use cron. On Windows, there's a similar functionality. Neither of it has anything at all to do with Perl - you'd use the same if you wanted to run a C or python program every hour.

    Abigail