1.把定时任务写到一个文件里面
*/1 *1 * * * echo "hello" >> tt.txt
2.使用shell读取定时任务文件写入到 crontab 里面
#!/bin/bash
# 1.start crontab
/bin/systemctl start crond.service
# 2.remove old crontab
echo > /var/spool/cron/website
# 3.add crontab
cat cron.txt | while read line
do
echo "$line" >> /var/spool/cron/website
done
# 4.reload crontab
/bin/systemctl reload crond.service
原文链接:https://www.f2er.com/bash/389256.html