Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

executing perl script at a certain time/day

by Anonymous Monk
on Dec 06, 2002 at 02:48 UTC ( #217970=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello All Monks, Are there any ideas out there about automating script execution for a certatin day/time. Thanks

Comment on executing perl script at a certain time/day
Re: executing perl script at a certain time/day
by pfaut (Priest) on Dec 06, 2002 at 02:53 UTC
    Use your system's scheduling capabilities. On *nix, use cron. On Windows, use at (or Scheduled Tasks somewhere under Control Panel/Administrative Tools/System Tools).
Re: executing perl script at a certain time/day
by Massyn (Hermit) on Dec 06, 2002 at 05:58 UTC

    The simplest way would be to do read the time through the localtime(time) function. I don't totally agree with using cron or AT. Do something like this, and your script will stay cross-platform (something I need).

    ... while(1) { sleep(60); @time = localtime(time); if(($time[2] == 10) && ($time[1] == 0) { #do what ever you want to do at 10am } }

    I hope this helps..

    Thanks!

    #!/massyn.pl

    You never know important a backup is until the day you need it.

Re: executing perl script at a certain time/day
by Chief of Chaos (Friar) on Dec 06, 2002 at 07:41 UTC
    Hi,
    another way is to compute the difference between NOW and starttime and to sleep this time in seconds.
    #!/usr/local/bin/perl -w use strict; use Time::Local; use POSIX qw(ctime difftime mktime); my $starttime = '08.12.02 03:00:00'; my $nowtime = time; #time in sec since 1970 my $sTime = 0; my $sleepSec = 0; #parsing the input (start) time if ($starttime =~ /^\s*(\d{1,2})\.(\d{1,2})\.(\d{2})\s+(\d{1,2})\:(\d{ +1,2})\:(\d{1,2})\s*$/) { # mktime(sec,min,hr,day,month,year) # month (0..11); year = 0 => 1900 , year = 100 => 2000 $sTime = mktime($6,$5,$4,$1,$2-1,100+$3); } print "Now-Date = ", ctime($nowtime); print "Start-Date = ", ctime($sTime); $sleepSec = difftime($sTime,$nowtime); if ($sleepSec>0) { print "Want to sleep : $sleepSec seconds\n"; # sleep ($sleepSec); } else { print "Shit I missed my starttime...\n"; }
        cool
        I did not know that this module exists.
        Than I would prefer to use the Schedule::ByClock module.
        (Why invent the wheel a second time ??)
Re: executing perl script at a certain time/day
by mce (Curate) on Dec 06, 2002 at 12:24 UTC
    Hi,

    As I am a Tivoli consultant, I should point out that there is an excellent tool called Tivoli Workload Scheduler to do this.

    You can always send me a mail if you want to know more about this.

    But, since PM is a non profit organisation, I should confirm that you could use cron or at instead :-).


    ---------------------------
    Dr. Mark Ceulemans
    Senior Consultant
    IT Masters, Belgium

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2014-09-30 13:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (369 votes), past polls