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

How would you make a script that edits a user's crontab file. I'm using mrtg, and rrdtool. I've made a web page that creates the mrtg cfg file. I'd also like for it to add an entry into crontab. I think the user that it runs under is wwwrun. Any hints on how to do this?

Replies are listed 'Best First'.
Re: script to add to crontab
by belg4mit (Prior) on May 08, 2002 at 00:16 UTC
Re: script to add to crontab
by graff (Chancellor) on May 08, 2002 at 02:44 UTC
    Would it be acceptable to use "at" instead of "cron"? That would be simple, especially if the job/script being submitted with "at" includes something like the following as the first thing to do:
    at now + $interval this_same_script
    In other words, instead of using the crontab file to run a given script at regular intervals, use "at" to start the job the first time, and craft the script that "at" is running so that it schedules itself to run again after the desired length of time.

    Running "at" at the beginning of the script being scheduled will make sure that the schedule doesn't slip too much with each successive run.

Re: script to add to crontab
by kappa (Chaplain) on May 08, 2002 at 13:26 UTC
    Use crontab(1) utility. Run it as open CRONTAB 'crontab -l|' to get your current crontab on the standard output, modify it, and then open CRONTAB '|crontab -' to get it installed. This is the only way to edit crontabs for mere mortals as designed by cron author.