使用脚本编写cronjob

时间:2020-09-04 16:43:13

标签: shell jenkins cron

这是我第一次尝试设置cronjob以自动在Jenkins中进行更新。 目前,我到目前为止已完成以下操作:

1. sudo crontab -e # opens  the cron tab which will/should put the file in /var/spool/cron
2. @daily yum update  # running  the updates daily

这可以解决问题,但

  1. 当我尝试执行sudo cd /var/spool/cron时,我看不到任何crontab。但是当我做sudo crontab -l时,它显示了@daily yum updates
  2. 如何通过脚本(例如云初始化脚本)将内容@daily yum updates写到crontab

1 个答案:

答案 0 :(得分:0)

一种方法是-

#write out current crontab
crontab -l > mycron
#echo new cron into cron file
echo "@daily yum updates" >> mycron
#install new cron file
crontab mycron
rm mycron