LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   making an entry in crontab through code (perl) (https://www.linuxquestions.org/questions/programming-9/making-an-entry-in-crontab-through-code-perl-179796/)

akaash 05-09-2004 10:33 PM

making an entry in crontab through code (perl)
 
I want to make an entry in system crontab file . How can i do that by perl code . Where is the cron situated ; which file?

HOw can i do that ?

MarkBurke 05-15-2004 02:24 PM

Each user which has access to cron, will be able to run the command called crontab. Cron matches the first 5 fields of each crontab entry, and if the system date/time matches with the entry, then the command is executed. There is a seperate crontab for each user, including root.

As each user, you could run

crontab -e
The type vi commands to edit the crontab file. (i to insert, r to replace one char, x to delete a char, then type :q! to quit without save, or :wq to exit and save changes)

The crontab command is in this form:

Hour Minute DayOfMonth MonthOfYear DayOfWeek /someprogram args

Use * to indicate match any value of that field

Here's an example for sunday at 6am

6 0 * * 0 /bin/ls > /tmp/ls.txt

The 5th field is 0 for Sunday, fields are 0 through 6 for Sunday through Saturday. The day of month should have values from 1 to 31. You can do ranges like 1-31 or comma ranges like 0,5,10,15,20,25,30,35,40,45,50,55,60 (notice no spaces, because that moves to the next field) in the Minute field to run the command every 5 minutes.

Good luck,
I'm not sure on editing crontabs with perl, but the crontab file is an ascii file, but there are probably considerations to take into account with writing to the file, as cron constantly reads the file.

Probably you can do your crontab as a perl input file, and then run

crontab createdFile.txt

to install the new cron file (the entire thing)

Good luck again.

pragti 05-17-2004 03:36 AM

Hi
the cron files are in the directory /var/spool/cron/(username)


All times are GMT -5. The time now is 04:33 AM.