Gossamer Forum
Home : General : Perl Programming :

CRON JOBS on NT FAQ

Quote Reply
CRON JOBS on NT FAQ
This will solve I hope all Questions regarding Cron Jobs on Win NT Servers

This is taken from the help menu of the Active Perl for Windows Distribution(open source)
you can get it at http://www.ActiveState.com

Love
Klaus



START QUOTE Active State Perl (Win Perl Toc)
#################################################################################
How do I schedule jobs on Win32 platforms?

The UNIX cron utility doesn't exist on Win32 platforms.

For Windows NT, a scheduling tool called AT is available. Unlike the UNIX cron utility, AT doesn't store its schedule
in a flat file, but is configured using command-line arguments. Note the AT command seems to be very picky
about syntax. Here is one example:

at 23:37 /interactive /every:M,T,W,Th,F,S,Su cmd /c "c:\perl\bin\perl.exe c:\test.pl"

If you don't like the command-line version of AT, there's a GUI version, WinAT, which is available with the
Windows NT Resource Kit. The "Schedule" service must be running when your job is supposed to happen.

Note that you may have problems when running AT or WinAT if the scheduled program or script requires any
special rights or permissions other than those held by "System" (ie, if it is working across computers or NT
domains). This is because NT does not properly allow you to run preinstalled NT services, such as the "Schedule"
service as a user with network priveleges. It may look like you can set the scheduler to login as a user with
network priveledges, but the service just does not recognize that user's right's and permissions and the System
userid has only local permissions.

An all-Perl cron-like solution exists at http://www.megadodo.demon.co.uk/perl/ which uses a familiar Unix-like
crontab file. This script can be ran as an NT Service (see How do I set up a Perl script as an NT Service?). When
you create your own NT service, NT lets you set the useid/password pair, and these services do recognize that
userid's rights and permissions. Hence, the scheduled program or script will have the necessary rights.

There are a few commercial cron-like schedulers. NTcrond, is available from ifdef software: http://www.ifdef.com/
and AutoTask2000 is available from http://www.cypressnet.com/ . These programs should recognize the rights and
priveleges of the userid you set their service to run under to enable the scheduled program or script to have the
necessary rights.

For Windows 95, there's a System Agent available with the Microsoft Plus! Pack. Also, there are several shareware
scheduling utilities, notably LaunchPad and Metz Scheduler. These can be found on a good shareware search
engine, such as http://www.shareware.com/ . There is also an optional "Task Scheduler" component with IE4.01
and Windows 98.

Because scheduled jobs on Windows NT run as a service (see What is a Windows NT service?), you need to take
special steps to make sure that files and environment variables are available to your script.

In some instances, Perl's internal sleep function might be an appropriate means of scheduling. For example:

$seconds = 180;
sub action;
while(1) {
&action;
sleep($seconds);
}


#####################################################################################
END QUOTE

------------------
###################
The S-mart Links Project
integrate full Shopping
Functionality into Links
http://smartlinks.i-go.to/
##################
Quote Reply
Re: CRON JOBS on NT FAQ In reply to
Thanks for posting this information. It will assist NT programmers. I did figure out how to use this utility about three weeks ago.

Note: The NT Resource Kit comes with WinAt, which provides a GUI based administrative console for creating scheduled jobs. It is a wonderful tool. Yes, you can use the command prompt to create scheduled jobs, but the GUI console is wonderful!

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: CRON JOBS on NT FAQ In reply to
Very weird. I had the AT Scheduler running a perl script at 12:00 a.m. every morning. It was running fine until last Thursday, 07/15/99. The only thing that I did differently with the file (on Thursday) that I am running is that I broke it up into two modules: configuration and perl file. The perl file executes properly via the web browser. However, when I try testing the Scheduler, the index file is not built...only through the browser.

I tested the Scheduler with two different files: 1) Included all configuration information, and 2) Modular files (with config and Perl). The Scheduler ran the file fine with the former format. But the index file was not built with the latter format.

Why does the Scheduler not run the Perl file that is calling another file? I do have the following line:

Code:
require "build.cfg";

in the build.pl file.

Anyone seen weird Scheduler behavior like this?

This is very weird since I have scripts running on my UNIX server via Crontab that "require" other files (configuration) and the scripts run smoothly. (Example: Links)

Weird....

TIA.


------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited July 19, 1999).]

[This message has been edited by Eliot (edited July 19, 1999).]
Quote Reply
Re: CRON JOBS on NT FAQ In reply to
Task Scheduler that comes with plus and Microsoft Internet Explorer 5 is way better. Its graphical interface is good, because you link to the program by a browse window. You can setup up multiple runtimes so its executed every six hours.

------------------
------------------------------------------
Lavon Russell
LookHard! Search
http://www.lh.yi.org
webmaster@lh.yi.org
Quote Reply
Re: CRON JOBS on NT FAQ In reply to
Bmxer,

Thanks for the suggestion. However, it does not address my problem. I am using AT Scheduler and it provides a nice GUI interface that allows files to execute multiple time periods and days. The problem as I stated is that I have a perl file that has a configuration file associated with it.
It does not run. If I put all the configurations in the perl file, it runs just fine.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us