crontab -l查看任务
crontab -e便捷定时编辑任务
当我们编辑完定时任务过后,记得重载一遍crond
systemctl reload crond.service
启动、停止、重启服务↓
systemctl start crond.service
systemctl stop crond.service
systemctl restart crond.service
为了方便我们可以把crontab设置成开机自启 在 /etc/rc.d/rc.local 脚本中加入 systemctl start crond.service即可
查看定时任务
[root@localhost ~]# crontab -l
1 1 * * * mysql -uzabbix -pzabbix zabbix -e "CALL partition_maintenance_all('zabbix')"
每天22点1分执行mysql -uzabbix -pzabbix zabbix -e "CALL partition_maintenance_all('zabbix')"命令
查看脚本执行情况
[root@localhost ~]# cat /var/log/cron
Apr 24 22:01:01 localhost CROND[11793]: (root) CMD (mysql -uzabbix -pzabbix zabbix -e "CALL partition_maintenance_all('zabbix')")
Apr 24 22:01:01 localhost CROND[11794]: (root) CMD (run-parts /etc/cron.hourly)
Apr 24 22:01:01 localhost run-parts(/etc/cron.hourly)[11794]: starting 0anacron
Apr 24 22:01:01 localhost run-parts(/etc/cron.hourly)[11804]: finished 0anacron
Apr 24 22:01:01 localhost run-parts(/etc/cron.hourly)[11794]: starting 0yum-hourly.cron
Apr 24 22:01:01 localhost run-parts(/etc/cron.hourly)[11810]: finished 0yum-hourly.cron
Apr 24 22:17:20 localhost crontab[11873]: (root) LIST (root)
网友评论