linux鐨勫畾鏃朵换鍔?-crontab
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux鐨勫畾鏃朵换鍔?-crontab相关的知识,希望对你有一定的参考价值。
鏍囩锛?/p>
cron鏄竴涓猯inux涓嬬殑瀹氭椂鎵ц宸ュ叿锛屽彲浠ュ湪鏃犻渶浜哄伐骞查鐨勬儏鍐典笅杩愯浣滀笟銆傜敱浜嶤ron 鏄疞inux鐨勫唴缃湇鍔★紝浣嗗畠涓嶈嚜鍔ㄨ捣鏉ワ紝鍙互鐢ㄤ互涓嬬殑鏂规硶鍚姩銆佸叧闂繖涓湇鍔★細
/sbin/service crond start //鍚姩鏈嶅姟
/sbin/service crond stop //鍏抽棴鏈嶅姟
/sbin/service crond restart //閲嶅惎鏈嶅姟
/sbin/service crond reload //閲嶆柊杞藉叆閰嶇疆
/sbin/service crond stop //鍏抽棴鏈嶅姟
/sbin/service crond restart //閲嶅惎鏈嶅姟
/sbin/service crond reload //閲嶆柊杞藉叆閰嶇疆
浣犱篃鍙互灏嗚繖涓湇鍔″湪绯荤粺鍚姩鐨勬椂鍊欒嚜鍔ㄥ惎鍔細
鍦?etc/rc.d/rc.local杩欎釜鑴氭湰鐨勬湯灏惧姞涓婏細
/sbin/service crond start
/sbin/service crond start
1.鐩存帴鐢╟rontab鍛戒护缂栬緫
cron鏈嶅姟鎻愪緵crontab鍛戒护鏉ヨ瀹歝ron鏈嶅姟鐨勶紝浠ヤ笅鏄繖涓懡浠ょ殑涓€浜涘弬鏁颁笌璇存槑锛?/span>
crontab -u //璁惧畾鏌愪釜鐢ㄦ埛鐨刢ron鏈嶅姟锛屼竴鑸瑀oot鐢ㄦ埛鍦ㄦ墽琛岃繖涓懡浠ょ殑鏃跺€欓渶瑕佹鍙傛暟
crontab -l //鍒楀嚭鏌愪釜鐢ㄦ埛cron鏈嶅姟鐨勮缁嗗唴瀹?/span>
crontab -r //鍒犻櫎娌′釜鐢ㄦ埛鐨刢ron鏈嶅姟
crontab -e //缂栬緫鏌愪釜鐢ㄦ埛鐨刢ron鏈嶅姟
姣斿璇磖oot鏌ョ湅鑷繁鐨刢ron璁剧疆锛歝rontab -u root -l
鍐嶄緥濡傦紝root鎯冲垹闄red鐨刢ron璁剧疆锛歝rontab -u fred -r
鍦ㄧ紪杈慶ron鏈嶅姟鏃讹紝缂栬緫鐨勫唴瀹规湁涓€浜涙牸寮忓拰绾﹀畾锛岃緭鍏ワ細crontab -u root -e
杩涘叆vi缂栬緫妯″紡锛岀紪杈戠殑鍐呭涓€瀹氳绗﹀悎涓嬮潰鐨勬牸寮忥細*/1 * * * * ls >> /tmp/ls.txt
杩欎釜鏍煎紡鐨勫墠涓€閮ㄥ垎鏄鏃堕棿鐨勮瀹氾紝鍚庨潰涓€閮ㄥ垎鏄鎵ц鐨勫懡浠わ紝濡傛灉瑕佹墽琛岀殑鍛戒护澶锛屽彲浠ユ妸杩欎簺鍛戒护鍐欏埌涓€涓剼鏈噷闈紝鐒跺悗鍦ㄨ繖閲岀洿鎺ヨ皟鐢ㄨ繖涓剼鏈氨鍙互浜嗭紝璋冪敤鐨勬椂鍊欒寰楀啓鍑哄懡浠ょ殑瀹屾暣璺緞銆傛椂闂寸殑璁惧畾鎴戜滑鏈変竴瀹氱殑绾﹀畾锛屽墠闈簲涓?鍙蜂唬琛ㄤ簲涓暟瀛楋紝鏁板瓧鐨勫彇鍊艰寖鍥村拰鍚箟濡備笅锛?/span>
鍒嗛挓 (0-59)
灏忔檪(0-23)
鏃ユ湡(1-31)
鏈堜唤(1-12)
鏄熸湡(0-6) //0浠h〃鏄熸湡澶?/span>
闄や簡鏁板瓧杩樻湁鍑犱釜涓壒娈婄殑绗﹀彿灏辨槸"*"銆?/"鍜?-"銆?,"锛?浠h〃鎵€鏈夌殑鍙栧€艰寖鍥村唴鐨勬暟瀛楋紝"/"浠h〃姣忕殑鎰忔€?"*/5"琛ㄧず姣?涓崟浣嶏紝"-"浠h〃浠庢煇涓暟瀛楀埌鏌愪釜鏁板瓧,","鍒嗗紑鍑犱釜绂绘暎鐨勬暟瀛椼€備互涓嬩妇鍑犱釜渚嬪瓙璇存槑闂锛?/span>
姣忓ぉ鏃╀笂6鐐?/span>
-----------------
0 6 * * * echo "Good morning." >> /tmp/test.txt //娉ㄦ剰鍗曠函echo锛屼粠灞忓箷涓婄湅涓嶅埌浠讳綍杈撳嚭锛屽洜涓篶ron鎶婁换浣曡緭鍑洪兘email鍒皉oot鐨勪俊绠变簡銆?/span>
姣忎袱涓皬鏃?/span>
-----------------
0 */2 * * * echo "Have a break now." >> /tmp/test.txt
鏅氫笂11鐐瑰埌鏃╀笂8鐐逛箣闂存瘡涓や釜灏忔椂锛屾棭涓婂叓鐐?/span>
-----------------
0 23-7/28 * * * echo "Have a good dream锛氾級" >> /tmp/test.txt
姣忎釜鏈堢殑4鍙峰拰姣忎釜绀兼嫓鐨勭ぜ鎷滀竴鍒扮ぜ鎷滀笁鐨勬棭涓?1鐐?/span>
-----------------
0 11 4 * 1-3 command line
1鏈?鏃ユ棭涓?鐐?/span>
-----------------
0 4 1 1 * command line
姣忔缂栬緫瀹屾煇涓敤鎴风殑cron璁剧疆鍚庯紝cron鑷姩鍦?var/spool/cron涓嬬敓鎴愪竴涓笌姝ょ敤鎴峰悓鍚嶇殑鏂囦欢锛屾鐢ㄦ埛鐨刢ron淇℃伅閮借褰曞湪杩欎釜鏂囦欢涓紝杩欎釜鏂囦欢鏄笉鍙互鐩存帴缂栬緫鐨勶紝鍙彲浠ョ敤crontab -e 鏉ョ紪杈戙€俢ron鍚姩鍚庢瘡杩囦竴浠介挓璇讳竴娆¤繖涓枃浠讹紝妫€鏌ユ槸鍚﹁鎵ц閲岄潰鐨勫懡浠ゃ€傚洜姝ゆ鏂囦欢淇敼鍚庝笉闇€瑕侀噸鏂板惎鍔╟ron鏈嶅姟銆?/span>
2.缂栬緫/etc/crontab 鏂囦欢閰嶇疆cron
cron鏈嶅姟姣忓垎閽熶笉浠呰璇讳竴娆?var/spool/cron鍐呯殑鎵€鏈夋枃浠讹紝杩橀渶瑕佽涓€娆?etc/crontab锛屽洜姝ゆ垜浠厤缃繖涓枃浠朵篃鑳借繍鐢╟ron鏈嶅姟鍋氫竴浜涗簨鎯呫€傜敤crontab閰嶇疆鏄拡瀵规煇涓敤鎴风殑锛岃€岀紪杈?etc/crontab鏄拡瀵圭郴缁熺殑浠诲姟銆傛鏂囦欢鐨勬枃浠舵牸寮忔槸锛?/span>
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root //濡傛灉鍑虹幇閿欒锛屾垨鑰呮湁鏁版嵁杈撳嚭锛屾暟鎹綔涓洪偖浠跺彂缁欒繖涓笎鍙?br />HOME=/ //浣跨敤鑰呰繍琛岀殑璺緞,杩欓噷鏄牴鐩綍
# run-parts
01 * * * * root run-parts /etc/cron.hourly //姣忓皬鏃舵墽琛?etc/cron.hourly鍐呯殑鑴氭湰
02 4 * * * root run-parts /etc/cron.daily //姣忓ぉ鎵ц/etc/cron.daily鍐呯殑鑴氭湰
22 4 * * 0 root run-parts /etc/cron.weekly //姣忔槦鏈熸墽琛?etc/cron.weekly鍐呯殑鑴氭湰
42 4 1 * * root run-parts /etc/cron.monthly //姣忔湀鍘绘墽琛?etc/cron.monthly鍐呯殑鑴氭湰
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root //濡傛灉鍑虹幇閿欒锛屾垨鑰呮湁鏁版嵁杈撳嚭锛屾暟鎹綔涓洪偖浠跺彂缁欒繖涓笎鍙?br />HOME=/ //浣跨敤鑰呰繍琛岀殑璺緞,杩欓噷鏄牴鐩綍
# run-parts
01 * * * * root run-parts /etc/cron.hourly //姣忓皬鏃舵墽琛?etc/cron.hourly鍐呯殑鑴氭湰
02 4 * * * root run-parts /etc/cron.daily //姣忓ぉ鎵ц/etc/cron.daily鍐呯殑鑴氭湰
22 4 * * 0 root run-parts /etc/cron.weekly //姣忔槦鏈熸墽琛?etc/cron.weekly鍐呯殑鑴氭湰
42 4 1 * * root run-parts /etc/cron.monthly //姣忔湀鍘绘墽琛?etc/cron.monthly鍐呯殑鑴氭湰
澶у娉ㄦ剰"run-parts"杩欎釜鍙傛暟浜嗭紝濡傛灉鍘绘帀杩欎釜鍙傛暟鐨勮瘽锛屽悗闈㈠氨鍙互鍐欒杩愯鐨勬煇涓剼鏈悕锛岃€屼笉鏄枃浠跺す鍚嶄簡銆?/span>
以上是关于linux鐨勫畾鏃朵换鍔?-crontab的主要内容,如果未能解决你的问题,请参考以下文章
17.4-uC/OS-III娑堟伅绠$悊锛堜换鍔℃秷鎭槦鍒楋級