-1

I need to edit cron job name on list of hosts. Considering the number of hosts, can we have a script to edit cron job name?

Example: /var/spool/cron has the following cron job:

00 * * * * /home/app2/limit_proc_status_2048.sh >> /export/home/app2/limit_proc_status.txt

I need to find script to edit the decimal 2048 to 4096.

1

To modify a crontab entry (these are schedules and commands, they don't have names), you would have to

  1. dump the current crontab to a file
  2. modify the file
  3. reload the crontab from the file

The first and last steps could be done with

crontab -l >crontab.old

and

crontab crontab.new

Note that loading the crontab from a file like this replaces all existing crontab entries for the current user.

The modification that happens between these two operations may be a simple sed substitution:

sed 's/limit_proc_status_2048\.sh/limit_proc_status_4096.sh/' crontab.old >crontab.new

The substitution pattern needs to be specific enough that it only modifies the appropriate lines in the file.

It may be a good idea to leave both crontab.old and crontab.new around, in case something goes wrong.


To make it easier to modify jobs, it may often be better to schedule a script that runs the job. If, in your case, your crontab called a script that in turn called limit_proc_status_2048.sh and that arranged with the redirection to a log file etc., then you would not need to muck about with crontab at all. The only thing that would have needed changing is that script.

This is in particular true of jobs that may need extra logic and setup before they run, or of jobs that consists solely of a complex command (I usually write a short script, and schedule that instead, for anything longer than a single simple command).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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