Help updating cron entry using regular expressions

Posted by Uday on Super User See other posts from Super User or by Uday
Published on 2010-06-03T05:53:15Z Indexed on 2010/06/03 5:56 UTC
Read the original article Hit count: 210

Filed under:
|

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

© Super User or respective owner

Related posts about unix

Related posts about cron