欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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}