Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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/foo.sh -b 1 -h 4 > foo_output.sh 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
add comment

1 Answer

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
script-to-edit.sh 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 script-to-edit.sh might do,

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

Your Answer

 
discard

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.