PDA

View Full Version : Bash adjusting/editing crontab easily, appending new cronjob



Fli
07-29-2023, 08:28 AM
This seems to be easy way to edit Linux Crontab using bash/CLI:

# export current cronjobs to file:
crontab -l > file

# do editing, like replace word search by word replace:
sed -i "s/search/replace/g" file

# import file:
crontab file

How to just add/append new cronjob to crontab. Highlighted text is what is being append.:

echo -e "$(crontab -l 2>/dev/null)\n* * * * * bash $HOME/scripts/script 2&1>/dev/null &" | crontab -