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

Hiya people! Hope all is good. People, I needed some help -- how can I get a perl file to run automatically everynight at 12:00am or every hour or something like that (basically it should run to check if the current date has passed the date value in an included MS Access database file) I need to know this for a Win NT machine. PLEASE HELP :-) Thanks in advace, Surya Please email me if I wasn't able to propose my question correctly (questions@withu4u.com). Thanks.
  • Comment on How to automatically execute a perl file....

Replies are listed 'Best First'.
Re: How to automatically execute a perl file....
by bastard (Hermit) on Jul 26, 2001 at 06:46 UTC
    Well the first two answers are not perl based.

    On a unix system you should probably use cron.

    On a windows machine something like Norton Scheduler should work.

    The basic way to do this in perl is thus:

    while (1) { <place code here> sleep(86400); }
    Let it run in the background. It will sleep for 24 hrs (86400 seconds) then repeat the loop.
    This may have some problems (a day is not exactly 24 hrs).

    Another way to do it is to sleep for a lesser interval and do a check for the time passing then execute whatever code is needed.

    I would reccommend looking into a separate scheduling agent though. Thats what they do best.

Re: How to automatically execute a perl file....
by bikeNomad (Priest) on Jul 26, 2001 at 09:13 UTC
    If you explore your computer in the Windoze Explorer, you'll find a pseudo-folder underneath My Computer that's called Scheduled Tasks. This can be made to work for you. Find out how. There's adequate on-line help.
Re: How to automatically execute a perl file....
by Anonymous Monk on Jul 26, 2001 at 12:22 UTC
    I suggest you use WinNT's 'at' scheduler; it comes bundled with WinNT. Just remember to start the Scheduler service before using.

    Here's a quick guide:

    http://www.winntmag.com/Articles/Index.cfm?ArticleID=3131

    jcr

      But be sure to either use the Task Scheduler and the associated GUI (should be your option if it is there already), or the default WinNT Scheduler with the at command. The at command does *not* work reliably with the Task Scheduler (there are several MS Knowledgebase articles documenting that).

      For choosing the type of scheduling service, my advice would be to choose the one that is on the server by default. Taking into account the fact that the Task Scheduler is the more modern version, and nearly impossible to uninstall cleanly once installed by a friendly other component like Internet Explorer or parts of the BackOffice Suite, the usual choice for a server would probably be the Task Scheduler (so no at command, just GUI).

      Christian Lemburg
      Brainbench MVP for Perl
      http://www.brainbench.com

Re: How to automatically execute a perl file....
by MZSanford (Curate) on Jul 26, 2001 at 12:33 UTC
    as a side note, if you are using the at scheduler, or the scheduled tasks, i do not know how they will take to the command line of `perl myscript.pl`, so you may need to run it through pl2bat first.
    Thus spake the Master Programmer:
    "When you have learned to snatch the error code from the trap frame, it will be time for you to leave."
    -- The Tao of Programming
      No longer necessary. If perl is in the PATH, and PATHEXT contains the .pl type, then you should be able to type
      myscript
      and have the thing work.

      Incidentally I had some trouble with the command line to execute in the NT task scheduler. Here's what I'm actually using

      C:\WINNT\system32\CMD.EXE /c "perl w:\Admin\scripts\end_of_day.pl 1> +w:\logs\eod.log 2>w:\logs\eod.err "
      (Notice that I don't practice what I preach :))
        Thanks a lot guys for all your help. I really appreciate it!! Have a good day :-) Surya