ITPub博客

首页 > Linux操作系统 > Linux操作系统 > crontab使用心得

crontab使用心得

Linux操作系统 作者:ahmmh 时间:2015-01-27 11:14:47 0 删除 编辑

crontab使用心得

1.查看crontab说明

Linux代码  

[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服务命令和当前状态

Linux代码  

[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配置

Linux代码  

[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编辑模式)

Linux代码  

[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配置

Linux代码  

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

6.查看crontab日志

Linux代码  

[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)  

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30093414/viewspace-1416587/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-01-05

  • 博文量
    53
  • 访问量
    70781