Linux, Shell脚本为用户添加Crontab计划任务

比较简单,这样就可以了

cat > /var/spool/cron/root <<EOF
* * * * * /usr/sbin/ntpdate cn.pool.ntp.org >> /var/log/ntpdate.log
EOF

项目中的应用:

config.sh

---------------------------------------------------------------------------------------

crontabfile=/var/spool/cron/mysql
if [ -e $crontabfile ]; then
echo "*/10 * * * * /home/mysql/PEnterAccount/DaemonPEnterAccount.sh" >>$crontabfile
else
touch $crontabfile
echo "*/10 * * * * /home/mysql/PEnterAccount/DaemonPEnterAccount.sh" >>$crontabfile
fi
service crond restart

猜你喜欢

转载自zhangjiaweixt.iteye.com/blog/998158