crontab使用心得

1.查看crontab说明

[fwang5@szotautotest03 ~]$ more /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

 2.查询crontab服务命令和当前状态

[fwang5@szotautotest03 ~]$ sudo /sbin/service crond
Usage: /etc/init.d/crond {start|stop|status|restart|condrestart|try-restart|reload|force-reload}
[fwang5@szotautotest03 ~]$ sudo /sbin/service crond status
crond (pid  20109) is running...

 

3.查看crontab配置

[fwang5@szotautotest03 ~]$ sudo crontab -u fwang5 -l
5 8 * * * /home/MSDOMAIN1/fwang5/work/weblogin-monitor/loginstart.sh &> /dev/null
0 9 * * * /home/MSDOMAIN1/fwang5/work/stash-user-monitor/start.sh &> /dev/null

 

4.编辑crontab配置(自动进入VI编辑模式)

[fwang5@szotautotest03 ~]$ sudo crontab -u fwang5 -e

5 8 * * * /home/MSDOMAIN1/fwang5/work/weblogin-monitor/loginstart.sh &> /dev/null
0 9 * * * /home/MSDOMAIN1/fwang5/work/stash-user-monitor/start.sh &> /dev/null
~
~
"/tmp/crontab.uDsLmb" 2L, 161C

 

5.删除crontab配置

[fwang5@szotautotest03 ~]$ sudo crontab -u fwang5 -r

 

6.查看crontab日志

[fwang5@szotautotest03 ~]$ sudo tail -f /var/log/cron
Apr  8 14:02:50 szotautotest03 crontab[24296]: (root) LIST (fwang5)
Apr  8 14:02:56 szotautotest03 crontab[24298]: (root) BEGIN EDIT (fwang5)
Apr  8 14:03:57 szotautotest03 crontab[24298]: (root) REPLACE (fwang5)
Apr  8 14:03:57 szotautotest03 crontab[24298]: (root) END EDIT (fwang5)
Apr  8 14:04:01 szotautotest03 crond[20109]: (fwang5) RELOAD (/var/spool/cron/fwang5)
Apr  8 14:10:20 szotautotest03 crontab[24314]: (root) LIST (fwang5)
Apr  8 14:29:15 szotautotest03 crontab[24323]: (root) LIST (fwang5)
Apr  8 14:35:53 szotautotest03 crontab[24385]: (root) LIST (fwang5)
Apr  8 14:36:22 szotautotest03 crontab[24387]: (root) BEGIN EDIT (fwang5)
Apr  8 14:37:49 szotautotest03 crontab[24387]: (root) END EDIT (fwang5)


 

你可能感兴趣的:(linux)