如何在Linux上的Shell脚本中添加crontab条目?

crontab -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?

crontab -e启动编辑器来编辑crontab条目。 但是如何在Linux上的shell脚本中添加crontab条目而又无需用户交互?

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.

请注意,此脚本行的更新不是原子的。 如果其他一些程序编辑crontab 文件的第一和第二所调用之间crontab中,编辑将丢失。 因此,使用此脚本时,请确保没有其他程序/管理员在编辑crontab。

Answered by Vivian.
薇薇安回答。

翻译自: https://www.systutorials.com/how-to-add-a-crontab-entry-from-a-shell-script-on-linux/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值