Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

hi I am trying to update a cron entry NOT by using crontab -e but by shell commands. For example the cron entry is like this:

10 * * * * /home/localuser/ -b 1 -h 4 > 2>&1

No i need edit the command line parameters part ONLY i.e

-b 1 -h 4

to something else which will be coming in from the user. First thing would be to write the crontab to a tmp file and then manipulate that temp file. Now, is there an easy way to edit that line using SED or something? The crude way wud be to delete that entire line, write a new line with the entire expression and then load that into the cron. I am not very good with regular expressions. My system supports sed -i so was thinking this could be done in a single line command. Thanks in advance

share|improve this question
up vote 2 down vote accepted

The basic steps for editing the crontab file with a script would go like this,

crontab -l > working-file.txt working-file.txt > edited-file.txt
crontab edited-file.txt

Depending on how the other lines in your crontab look (or may look in the future),
you can write a sed line to change the command of interest.
Here is an example of what the might do,

sed 's| \-b 1 \-h 4| -b XXX -h YYY|g'
share|improve this answer
hi thanks for the reply!. thanks it works.. – Uday Jun 3 '10 at 9:51

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.