Bash sciript to edit crontab
Hi,
I want to write a bash script that edits a crontab. For example the crontab may have mutiples entries; ***** /etc/service/start -c ***** /etc/test/test I want to for example edit the line ***** /etc/service/start -c to ***** /etc/service/start and save it. Thanks |
You can install a new crontab reading it from a file or from standard input. To modify an existing crontab you can retrieve it using option -l, then apply your changes and re-install it again. For example:
Code:
crontab -l | sed 's%/etc/service/start -c%/etc/service/start%' | crontab - |
If you just want to edit the crontab, look up man crontab. crontab -e at the command line edits the users crontab in an editor and when one exits the editor it updates the crontab. Using this command, you preserve the permissions of the user (including root, if so invoked).
Dave |
Thanks Guys.
This works a treat; crontab -l | sed 's%/etc/service/start -c%/etc/service/start%' | crontab - If I want to say though replace /etc/service/start -c anything as in (.*) with /etc/service/start. So replace /etc/service/start -c and anything after that. I'm not having much luck in getting my expression right though |
Here's an example:
>echo '/etc/serve/start -c'|sed 's:/etc/serve/start -c.*:/etc/service/start:' /etc/service/start |
All times are GMT -5. The time now is 08:39 PM. |