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

Re: cron or perl?

by andreychek (Parson)
on Jun 30, 2001 at 05:42 UTC ( #92861=note: print w/replies, xml ) Need Help??

in reply to cron or perl?

If you want to have a program sleep, and then run something every 15 minutes, you could write:
use strict; # Loop forever while(1) { some_function(); another_function(); # Sleep statement, in seconds # 15 minutes * 60 seconds in a minute = 900 seconds sleep 900; } sub some_function { foo; bar; } sub another_function { yada_yada; wocka_wocka; }
However, I am the type who would absolutally prefer to use cron to handle timing, as opposed to Perl. Cron is a wonderful resource, and I find it easier to use an existing resource then to recreate one. It's one thing if you will always stick to 15 minutes.. but what if you ever decide you don't want it to run on the weekends?

Secondly, by having your Perl program handle the time -- if you ever reboot, you'll need to rerun the program. Or create a startup script to do it for you. What if you end up with 15 of these scripts? Or 50? I would personally find it much easier to manage them with cron.

Lastly, a point could be raised about system resources. Having scripts running all the time uses memory. It may be easier on your system resources to have them only run when necessary. The other side of the coin is that depending on the script, it might take a lot of CPU time to fire up that script every 15 minutes, instead of leaving it in RAM where the system may cache it. But you'll have to do some benchmarks to work that out :-)

Replies are listed 'Best First'.
Re (tilly) 2: cron or perl?
by tilly (Archbishop) on Jun 30, 2001 at 05:49 UTC
    The best reason IMO to use cron. Configure cron right and error reporting is simplified down to just printing out any error messages before you exit. The right people will get emails with no further work in your program.

    That can be very useful for finding out about strange errors...

Re: Re: cron or perl?
by Anonymous Monk on Jun 30, 2001 at 20:57 UTC
    <minor nitpick>
    Your code does not execute some_function() and another_function() every 15 minutes, it puts a 15 minute pause in between, if each function took 5 minutes then it would run them every 25 minutes. To execute them every 15 minutes you would need to check the time() at the top of the loop and again at the bottom and adjust the sleep time accordinly which could still drift your loop by a fraction of a second with each itteration. I do second... errr fourth your suggestion to use cron.
    </minor nitpick>>

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://92861]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2018-03-18 04:30 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (228 votes). Check out past polls.