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

Hello Monks, I wrote a small script that needs to be able to run on a daily basis in order to work efficiently, but I'm not sure how to do this. I know under Liunx there is the whole crontab concept, but I am unfortunately not too familiar with it.

The problem is that I've created a web-based script that I want to be able to give to other people. For my self, I could simply find out how to edit my host's crontab and I would be set. For others without any computer experience, this might be able difficult task.

Is there a way to add a cronjob using Perl? I think the crontab is just a file, so could I just append a new line of information to that file in order to get the desired results. If I'm running this from the web, will I run into permission issues.

Any suggestions on the best way to setup a script to run daily would be greatly appreciated. Thanks in advance. -Eric

Replies are listed 'Best First'.
Re: auto run perl scripts
by Abigail-II (Bishop) on Jun 11, 2002 at 16:09 UTC
    Using crontab is the way to go. There isn't anything deep voodoo about cron. The crontab information is indeed stored in a file, but that doesn't mean adding something to the file is going to work. On many OSses, nothing will happen. You would usually have to use the crontab command, either interactively (using an editor), or by passing it a complete file. The crontab command checks the file for syntax errors, and then tells the cron daemon there's a new configuration file.

    You can automate that process, but details of how to do that differ between OSses. Personally, I think setup scripts that modify configuration information (like crontab entries) are a big no-no. If people cannot figure how to add a line (you can give them the line they need to add) to their crontab, they shouldn't run automated processes.

    Abigail

Re: auto run perl scripts
by stajich (Chaplain) on Jun 11, 2002 at 16:10 UTC
    Auto adding cronjobs is likely a bad idea. Speaking UN*X terms here,some systems have an /etc/cron.d/cron.allow which needs the username added before the user is allowed to add a cronjob. I really think you are going to need to assume that someone installing your script is a sysadmin or rethink your distribution strategy.

    You can make the admin's job easier by providing the pregenerated crontab information like producing a file that can be read-in like
    % cronatab -e < crontoload.in

    But know that admins may want to put scripts in certain places so you probably can't assume that your crontab will work perfectly every time depening on where perl is installed, the module dependancies, etc. I think that you are going to have to assume some sort of computer competency if someone is running linux and needs to run your script to optimize your CGI script's performance.

    As for pure-perl solutions, you could consider Schedule::Cron but I'm not sure how safe it is having never used it. It would run as userlevel daemon and if your webserver is running as nobody you won't be able to cleanup files produced by it.