How to add a crontab entry from a shell script on Linux?
Posted on In QAcrontab -e
will start an editor to edit the crontab entries. But how to add a crontab entry from a shell script on Linux without interaction from users?
You can try this piece of script:
(crontab -l; echo "@reboot echo "rebooted"";) | crontab -
Note that the update by this line of script is not atomic. If some other programs edit the crontab files between the first and second invokes of crontab
, the edits will be lost. Hence, make sure there is not other programs/admins editing the crontab when you use this piece of script.
Answered by Vivian.