首页 > 解决方案 > Writing a cronjob using a script

问题描述

This is the first time I am trying to setup the cronjob to automatically do updates in Jenkins. Currently, I have done the following so far:

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

This fixes the issue but

  1. when I try to do sudo cd /var/spool/cron I cannot see any crontab. But when I do sudo crontab -l it shows me @daily yum updates
  2. How can I write the content @daily yum updates to crontab via script (like cloud init script)?

标签: shelljenkinscron

解决方案


一种方法是——

#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

推荐阅读