shell 脚本编辑 crontab 任务
程序员文章站
2022-07-06 11:05:17
...
#!/bin/bash
SCHED_FILE="/home/liuyg/study/crontab_sched_file"
# check the sched file exist
if [ ! -f "${SCHED_FILE}" ]; then
touch ${SCHED_FILE}
fi
# stop cron
service cron stop
# replace cron file
echo " * * * * * date +'\%F \%T' >> /home/liuyg/study/test" > ${SCHED_FILE}
echo " * * * * * echo 'hello world' >> /home/liuyg/study/test" >> ${SCHED_FILE}
# start cron
service cron start
# crontab
crontab ${SCHED_FILE}
上一篇: 教你如何搭建一个时间服务器