Excuse me if it is a repeat. I have crontab entries which look like:
* * * * * sleep 15;/etc/opt/wer.sh
1 * * * * /opt/sfm/qwe/as.sh
How to insert a # on the line which contains a call to "as.sh" using sed?
How to uncomment it back?
You can use:
which will replace the start-line zero-width marker with a comment character for all lines containing
/as.sh
, as shown in the following example:But you need to keep in mind a couple of things.
cron
that it needs to re-read it. This is automatic if you use thecrontab
command itself but you may have to send a signal tocron
if you're editing the file directly.To get rid of the marker, use:
This is the opposite operation, it finds those lines containing
/as.sh
and substitute any#
character at the start of the line with nothing.To add the comment:
To remove the comment:
use crontab -e to modify the current user's crontab.