Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Way to add a scheduled task?

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Hi,

Does anyone know of a way to setup a scheduled task, from a Perl script? NB: This is a WINDOW's machine (yeah, I know... but its got things on it we need .. i.e the win32::OLE module, to link into Word).

If this was a UNIX server, then I'd just use a crontab option, but NT doesn't support that.

Anyone got any suggestions? I've tried looking around for a module, and even looked through all the Win32 modules, but none of them seemed to do what I need :(

TIA

Andy
 
I use a pure Perl cron utility to run my cron jobs. It has the added benefit of working almost exactly like a Unix cron, so there's little to be done when porting a script from Windows to Unix that writes to the cron file. It's only current drawback is that it does require a user to be logged into the machine at all times.

Give it a shot and see what you think.

- Rieekan
 
Hi,

Thanks for the reply. Looks very promising :) I'll install it, and see how it works. We have a machine on 24-7 anyway, with a UPS ... so the user should be able to remain on at all times, via a Terminal Connection.

Thanks again :)

Andy
 
I think AT was available under NT, I just verified it's there for XP - but that probably doesn't do you much good. I seem to remember there was also a utility distributed with the NT 4 Server Res Kit called WINAT. Either of those might be an option for you.

It looks like there might also be a Win32::TaskScheduler module that gives you access to the windows task scheduler.
 
You can also do this with perls native code but maybe not the most admirable way to do it.
Code:
$time = 9000;
while(1){
code.......

sleep($time);
}


haunter@battlestrata.com
 
Hi,

Thanks guys/gals :) I've managed to write a custom script to do this now. If anyone's interested, its as follows;

Code:
#!/perl 

use strict;
use File::Copy;

&init;

sub init {

   my @commands;
   open (READIT,"<crontab")  || die "Cant open crontab. Reason: $!";
    while (<READIT>) {
       push @commands, $_;
    }
   close(READIT);

   my $time = localtime();
   move("crontab","crontab.$time");
   print qq{Moving crontab to "crontab","crontab.$time"\n};

#   `del crontab`;

   open (READIT,">crontab")  || die "Cant open crontab. Reason: $!";
    print READIT "";
   close(READIT);   

   foreach (@commands) {
    	print "Running: $_ \n";
       `$_`;
   }

   sleep 30;
   &init; # restart init

}


This assumes you are using a file called "crontab", and each line contains a system command. E.g;

perl d:/path/to/script.pl --opts
perl d:/path/to/script2.pl --more-opts
perl d:/path/to/script2.pl --more --foo=1
..etc

Thanks again for the pointers :)

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top