Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Would someone suggest any handy command line (NOT web) tool or script which adds, enables and disables Cron jobs? I am looking, for example, for the following (or similar) behavior:

sh manageCron.sh -idJob 'job1' -addJob '* * * * * <do some job>'
sh manageCron.sh -dissableJob 'job1' 

crontab -e command is good for manual editing of crontab file, but I need to automate.

share|improve this question
up vote 1 down vote accepted

crontab -u USER -l will list the crontab to STDOUT.

crontab -u USER FILE will load FILE as crontab for USER.

Now the only thing that is missing is a way to identify your "jobs".

"AddJob" will add a line to the output of the current crontab and read it as new crontab.

"DisableJob" will just put a comment in front of your job-line,

"EnableJob" will remove a comment from your job-line.

share|improve this answer

This is the one I earlier used to manage, automate crontab, however not something really like what you are looking for. http://search.cpan.org/~scottw/Config-Crontab-1.33/Crontab.pm

CFEngine' cfperl has this kind of behaviour, which could be used to build on something like you are asking for. Crontab is actually a simple configuration file in itself and then cron(d) is what parses the individual crontabs (or the ones under /var/spool/cron/) and makes the list of events scheduled in the memory.

So, if you are looking for wrapping your configuration again over simplistic cron's crontab, then perhaps you are not looking for cron but some other scheduler which will trigger your jobs.

share|improve this answer

I don't know if an app to "automate" the maintenance of a crontab. What I do is keep a 'master' crontab, edit that, then use crontab ~/etc/app.cron or something similar. Then it would easy enough to create something to automate the modification of ~/etc/app.cron.

For named jobs how you want, you'll either have to create a mini database with the job names, or add the job name to a structured comment at the end of the crontab line.

share|improve this answer

You can automate cron jobs with crontab -e. Since crontab -e invokes the editor specified by $VISUAL, or $EDITOR if VISUAL is not set, specify some script as $VISUAL.

cat <<'EOF' >"$script"
#!/usr/bin/ed -s
1 2 3 4 5 new job #job2
VISUAL="$script" crontab -e
rm -f "$script"

There's no intrinsic notion of job names; you can easily make up one by adding a comment like #jobname at the end of each line as in the example above.

Instead of crontab -e, you may find it easier to dump the current file, edit it and install the new version or keep a master copy and install it when you change it. Using a master copy means that you must not edit the crontab through other means, or your changes will be overridden. Dumping the current file and editing it means that if something or someone else edits the crontab at the same time, whoever installs first will have their changes overridden; some versions of crontab prevent this by locking the file while crontab -e is in operation, but I don't know if Solaris's does.

share|improve this answer
+1 this is what I would use. – Icarus Dec 29 '11 at 3:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.