I understand there is a lot of documentation on editing crontabs via script, and I can do this by adding an entry with the following command:
line="* * * * * /my/folder/script.sh" ( crontab -l ; echo "$line" ) | crontab -
However, myself and a few others each have our own "sections" in our crontab under a superuser.
How can I insert this line under a keyword or string, such as underneath the line containing
SPECIAL_JOB so as not to disturb others' sections and entries? I don't want to just keep appending new jobs at the bottom of the crontab.
The cron entry would look like this:
# SPECIAL_JOB * * * * * /my/folder/script.sh
Ideally, I would delete the previous entry at this line to keep a single, fresh entry using this:
#remove entry crontab -l | grep -ve '/my/folder/script.sh' | crontab -