Linux 下crontab简单使用
0.個(gè)人標(biāo)記
caicongyang
http://blog.csdn.net/caicongyang
1.crontab
crontab是linux下的一個(gè)定時(shí)任務(wù),在sping中也有該機(jī)制
2.基本格式
* * * * * command
分 時(shí) 日 ?月 周 ?命令
3.命令
usage: crontab [-u user] filecrontab [-u user] [ -e | -l | -r ](default operation is replace, per 1003.2)-e (edit user's crontab)-l (list user's crontab)-r (delete user's crontab)-i (prompt before deleting user's crontab)-s (selinux context) crontab –u //設(shè)定某個(gè)用戶的cron服務(wù)。一般root用戶在運(yùn)行這個(gè)命令的時(shí)候須要此參數(shù)?
crontab –l //列出某個(gè)用戶cron服務(wù)的具體內(nèi)容?
crontab –r //刪除某個(gè)用戶的cron服務(wù)?
crontab –e //編輯某個(gè)用戶的cron服務(wù)?
crontab filename //以filename作為crontab的任務(wù)列表文件并加載?
比方說root查看自己的cron設(shè)置:crontab –u root –l?
再比如,root想刪除fred的cron設(shè)置:crontab –u fred –r?
在編輯cron服務(wù)時(shí)。編輯的內(nèi)容有一些格式和約定。輸入:crontab –u root –e?
4.又一次啟動(dòng)
改動(dòng)了crontab須要又一次啟動(dòng),下面命令分別提供了查看crontab的狀態(tài)和重新啟動(dòng)
#service crond status #service crond restart
5.列子
#每天早上6點(diǎn)10分?
10??? 6???? *???? *???? *???? date?
#每?jī)蓚€(gè)小時(shí)?
0???? */2?? *???? *???? *???? date?
#晚上11點(diǎn)到早上8點(diǎn)之間每?jī)蓚€(gè)小時(shí),早上8點(diǎn)?
0???? 23-7/2,8????? *???? *???? *???? date?
#每一個(gè)月的4號(hào)和每一個(gè)禮拜一到禮拜三的早上11點(diǎn)?
0???? 11??? 4???? *???? 1-3? date?
#1月1日早上4點(diǎn)?
0???? 4???? 1???? 1?????? *? date?
30 21 * * * /usr/local/etc/rc.d/lighttpd restart
上面的樣例表示每晚的21:30重新啟動(dòng)apache。
45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
上面的樣例表示每月1、10、22日的4 : 45重新啟動(dòng)apache。
10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart
上面的樣例表示每周六、周日的1 : 10重新啟動(dòng)apache。
0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart
上面的樣例表示在每天18 : 00至23 : 00之間每隔30分鐘重新啟動(dòng)apache。
0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart
上面的樣例表示每星期六的11 : 00 pm重新啟動(dòng)apache。
* */1 * * * /usr/local/etc/rc.d/lighttpd restart
每一小時(shí)重新啟動(dòng)apache
* 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart
晚上11點(diǎn)到早上7點(diǎn)之間,每隔一小時(shí)重新啟動(dòng)apache
0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart
每月的4號(hào)與每周一到周三的11點(diǎn)重新啟動(dòng)apache
0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart
一月一號(hào)的4點(diǎn)重新啟動(dòng)apache
我的CSDN博客地址:?http://blog.csdn.net/caicongyang?
轉(zhuǎn)載于:https://www.cnblogs.com/jzdwajue/p/7084278.html
總結(jié)
以上是生活随笔為你收集整理的Linux 下crontab简单使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 创建游戏场(实战演习)
- 下一篇: linux 其他常用命令