Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

WinDoze NT Automation Question

by Ducati (Beadle)
on Apr 24, 2001 at 18:21 UTC ( [id://75053]=perlquestion: print w/replies, xml ) Need Help??

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

I have written a Perl script which automates a bunch of command line tasks.

How do I get WinNT 4.0 Server to automatically run this script on a daily basis. In Linux/Unix there is CRON ... but I HAVE TO use WinNT Server ...

Currently, for testing, I run the script myself ... (perl script.pl) ... but that defeats the whole automation idea !! Any suggestions ??

Replies are listed 'Best First'.
Re: WinDoze NT Automation Question
by $code or die (Deacon) on Apr 24, 2001 at 18:26 UTC
    Have a look at the Scheduler service and the AT command (WINAT is on the resource kit).

    This isn't a Perl question though.

    $ perldoc perldoc
      Thankx for the help ... and I know that this is not a 100% perl question ... but this site is a whole lot better than using support.microsoft.com !!

      : -)

Re: WinDoze NT Automation Question
by Asim (Hermit) on Apr 24, 2001 at 20:17 UTC

    Others have mentioned AT and WinAT, and it is the standard NT solution for these problems. However, a number of people have, over the years, reported problems with using it with perl scrips and/or batch files -- go to MS's support site and look at article Q142432 for an example. For a sample, go to Activestate's mail archives and search on this subject -- I believe, if my memory serves me correctly, that someone even noted why it fails.

    From my own personal experience, I'd recommend using the newer "Scheduled Tasks" application, which, if I recall alright, is installed with IE 5.5. We've used it here for the last year to run perl-based reports that access over 1000+ servers, and perl scripts that died with AT (even after proper usernames were set) run fine with Scheduled Tasks

    Also recommended by others (although I've never used it mysely) is cron.pl

    ----Asim, known to some as Woodrow.

      I have used the "at" command to run automated jobs with perl scripts for long times (years) in different environments.

      I have *not* seen any problems with the "at" command itself, as long as it is used with the *originally installed NT scheduling service*, and *not* the Task Scheduler (which is the newer variant of the Scheduling Service, offers a GUI, and is installed by default by a variety of MS programs, not the least newer Internet Explorer versions and the BackOffice Suite).

      There are *definitively many problems* with using the "at" command in conjunction with the Task Scheduler. Don't do that. Use either "at" and the default NT scheduler, or the Task Scheduler.

      Reasons for using "at" are the usual reasons for using the command line (you can use automization for job setup, run automated deploy scripts, manipulate things easily from remote, etc.).

      Reasons for using the Task Scheduler mainly boil down to having a GUI and having no installation problems, since nearly all new packages for MS Server will install the Task Scheduler.

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

Re: WinDoze NT Automation Question
by mrmick (Curate) on Apr 24, 2001 at 18:27 UTC
    NT uses the AT command.

    Type :

    at/?
    to get help on the command.

    Mick
Re: WinDoze NT Automation Question
by petdance (Parson) on Apr 24, 2001 at 19:14 UTC
    There are a number of crons available for NT as well. Hit a search engine and look for +NT +cron.

    xoxo,
    Andy

    # Andy Lester  http://www.petdance.com  AIM:petdance
    %_=split';','.; Perl ;@;st a;m;ker;p;not;o;hac;t;her;y;ju';
    print map $_{$_}, split //,
    'andy@petdance.com'
    
Re: WinDoze NT Automation Question
by LordAvatar (Acolyte) on Apr 24, 2001 at 19:17 UTC

    You could wrap the main part of the script in an
    infinite loop with a call to sleep.

    Set sleep to an appropriate interval of seconds i.e.
    3600 (for one hour). Then run the program. It will execute
    the main code once every hour.

    If you want to simulate a cron
    and have it run everyday at 2:00PM, you would just set the
    sleep timer to 86400 (24*60*60) and first execute the program at 2:00pm today.

    while(1) {
             #execute some code here....
              sleep 86400  #Run code once every 24 hours.
    }
      But what if it takes an hour to run the script? It'll run an hour later every day...

      ---
      A fair fight is a sign of poor planning.

        Not that I would EVER do this for something that runs once a day - you can always do this:
        while (1) { my $loop_start = time; #.... code my $sleep_time = 86400 - (time - $loop_start); sleep ($sleep_time); }


        TIMTOWTDI!

        $ perldoc perldoc

        I suppose if that were the case you could adjust the
        sleep time back one hour (i.e) 60*60*23 instead of 60*60*24
        to account for the hour it takes the program
        to run. Just a guess off the top of my head...
        -LordAvatar

Re: WinDoze NT Automation Question
by the_slycer (Chaplain) on Apr 24, 2001 at 18:26 UTC
    "at" is the command that you want to look at. CLI, but there is a gui for it as well
Re: WinDoze NT Automation Question
by Anonymous Monk on Apr 24, 2001 at 21:23 UTC
    Schedule your .pl script to run using the at command. The AT command schedules commands and programs to run on a computer at a specified time and date. The Schedule service must be running to use the AT command.
    AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]] AT [\\computername] time [/INTERACTIVE] [ /EVERY:date[,...] | /NEXT:date[,...]] "command" \\computername Specifies a remote computer. Commands are scheduled + on the local computer if this parameter is omitted. id Is an identification number assigned to a scheduled command. /delete Cancels a scheduled command. If id is omitted, all +the scheduled commands on the computer are canceled. /yes Used with cancel all jobs command when no further confirmation is desired. time Specifies the time when command is to run. /interactive Allows the job to interact with the desktop of the +user who is logged on at the time the job runs. /every:date[,...] Runs the command on each specified day(s) of the we +ek or month. If date is omitted, the current day of the m +onth is assumed. /next:date[,...] Runs the specified command on the next occurrence o +f the day (for example, next Thursday). If date is omitt +ed, the current day of the month is assumed. "command" Is the Windows NT command, or batch program to be r +un.

    2001-04-25 Edit by Corion : Added CODE tags

Re: WinDoze NT Automation Question
by Anonymous Monk on Apr 24, 2001 at 20:36 UTC
    AT is the command line part thats been in Windows NT 4.0 sence it was released. But if you want a better, graphical version, that gives you ALOT more options, install IE 5.5 on the machine. That will install the latest and greatest graphical task scheduler.
Re: WinDoze NT Automation Question
by SgtClueLs (Novice) on Apr 24, 2001 at 21:08 UTC
    Depends if you need it to access local or remote PCs. Localy you should be able to us the AT Service. But if you're trying to access remote PCs (Especially drives in my case) I run into permissions issues. I'm currently using the MS SQL Server Agent / Jobs. Just setup a new scheduled job and have it run the perl script. Works great.
    They also make cron services for NT. Like AINTX's. You'll also need servany, or firedaemon for NT. You should then be able to setup that services to use X account for access issues.
Re: WinDoze NT Automation Question
by Biker (Priest) on Apr 25, 2001 at 15:23 UTC
    Check out the Schedule::ByClock.pm module from CPAN.
    See: http://www.cpan.org/modules/by-module/Schedule/


    f--k the world!!!!
    /dev/world has reached maximal mount count, check forced.
Re: WinDoze NT Automation Question
by BrotherAde (Pilgrim) on Apr 25, 2001 at 02:50 UTC

    To make this a perl-only answer, there's a perl-emulation of cron over at www.megadodo.demon.co.uk/perl/.

    To run it as a service, you need srvany.exe (No you don't! See $code or die's answer below...) from the NT resource kit.

    Hope that helps,
    BrotherAde

    Update:
    Thanks $code or die! I wasn't aware of Win32::Daemon. I'm using it now though...

Re: WinDoze NT Automation Question
by jwherbold (Novice) on Apr 25, 2001 at 19:01 UTC
    Click Start, Settings, Control Panel, and you should have an icon for the scheduler. Also check under my computer, I have set up my jobs (win2k) like:

    c:\perl\bin\perl.exe d:\perl_jobs\helpdesk\email_cases.pl

    john
Re: WinDoze NT Automation Question
by Anonymous Monk on Apr 25, 2001 at 14:22 UTC
    'at' is the winnt equivalent. i.e: at 15:00 /every:m,t,w cmd /c "perl script.pl" should work I think...
Re: WinDoze NT Automation Question
by Anonymous Monk on Apr 25, 2001 at 18:26 UTC
    Use the AT service! Try running Winaat or do AT /? on the command line. Stan
Re: WinDoze NT Automation Question
by Mungbeans (Pilgrim) on Apr 25, 2001 at 11:23 UTC
    AT is an option - you need to be careful how you set it up though because you may not be able to access some network drives and resources. Make sure the schedule service is started, and make sure it starts when the system reboots. You can set it up so that it logs in as you (which has more network privileges) or as the system account (which is less privileged).

    Also consider grabbing winat (on one of the NT resource discs I think) which gives you a slightly nicer gui front end.

    e.g to run master.bat at 1am every morning: at \\<MACHINE> 1:00AM /every:M,T,W,Th,F,S,Su cmd /c "e:\batch\master.b +at > e:\batch\logs\master0100AM"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://75053]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-25 13:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found