Linuxredhat

Programatically managing a user’s crontab

In Linux, there is a central crontab or scheduler for the entire system. Trying to schedule things through here is often messy and full of problems, luckily there is also a crontab for each user (unless intentionally disabled). Accessing this scheduler is simple, just run crontab -e and it will open in vi, you then edit the lines as you would any other cron.

But what if you want to edit this programatically – i.e. perform the same task on multiple computers? You dont want to log into each computer and make the change manually, but how do you script it?
I found the conversation at http://www.unix.com/shell-programming-scripting/17896-can-we-edit-crontab-using-shell-script.html that was discussing this and has a solution. According to user Just Ice

have your script …

a. crontab -l > $tmpfile
b. edit $tmpfile
c. crontab $tmpfile
d. rm $tmpfile

Leave a Reply