日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux启动脚本添加命令,Linux添加shell(.sh)脚本并添加定时任务

發(fā)布時(shí)間:2025/3/15 linux 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux启动脚本添加命令,Linux添加shell(.sh)脚本并添加定时任务 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、添加sheel腳本

1、首先創(chuàng)建一個(gè)執(zhí)行程序:vim a.sh

2、編輯: #!/bin/bash

python3? python.py?>> test2.log 2>&1

3、添加權(quán)限:chmod +x ./a.sh

4、查看執(zhí)行結(jié)果: ./a.sh

二、添加定時(shí)任務(wù)

安裝:apt-get install cron? ?(服務(wù)器環(huán)境下默認(rèn)都會(huì)安裝)

1、crontab –e : 修改 crontab 文件. 如果文件不存在會(huì)自動(dòng)創(chuàng)建。

2、crontab –l : 顯示 crontab 文件。

3、crontab -r : 刪除 crontab 文件。

4、crontab -ir : 刪除 crontab 文件前提醒用戶。

6,cron文件語法:

分???? 小時(shí)?? ?日?????? 月?????? 星期???? 命令

0-59? ?0-23?? 1-31?? 1-12? ? ? 0-6? ?command???? (取值范圍,0表示周日一般一行對應(yīng)一個(gè)任務(wù))

“*”代表取值范圍內(nèi)的數(shù)字,

“/”代表”每”,

“-”代表從某個(gè)數(shù)字到某個(gè)數(shù)字,

“,”分開幾個(gè)離散的數(shù)字

7,/sbin/service crond start //啟動(dòng)服務(wù)

/sbin/service crond stop //關(guān)閉服務(wù)

/sbin/service crond restart //重啟服務(wù)

/sbin/service crond reload //重新載入配置

14個(gè)超實(shí)用的Crontab使用實(shí)例

1.每天 02:00 執(zhí)行任務(wù)

0 2 * * * /bin/sh backup.sh

2.每天 5:00和17:00執(zhí)行任務(wù)

0 5,17 * * * /scripts/script.sh

3.每分鐘執(zhí)行一次任務(wù)

* * * * * /scripts/script.sh

4.每周日 17:00 執(zhí)行任務(wù)

0 17 * * sun /scripts/script.sh

5.每 10min 執(zhí)行一次任務(wù)

*/10 * * * * /scripts/monitor.sh

6.在特定的某幾個(gè)月執(zhí)行任務(wù)

* * * jan,may,aug * /script/script.sh

7.在特定的某幾天執(zhí)行任務(wù)

0 17 * * sun,fri /script/scripy.sh

在每周五、周日的17點(diǎn)執(zhí)行任務(wù)

8.在某個(gè)月的第一個(gè)周日執(zhí)行任務(wù)

0 2 * * sun [ $(date +%d) -le 07 ] && /script/script.sh

9.每四個(gè)小時(shí)執(zhí)行一個(gè)任務(wù)

0 */4 * * * /scripts/script.sh

10.每周一、周日執(zhí)行任務(wù)

0 4,17 * * sun,mon /scripts/script.sh

11.每個(gè)30秒執(zhí)行一次任務(wù)

我們沒有辦法直接通過上訴類似的例子去執(zhí)行,因?yàn)樽钚〉氖?min。但是我們可以通過如下的方法。

* * * * * /scripts/script.sh

* * * * * sleep 30; /scripts/script.sh

12.多個(gè)任務(wù)在一條命令中配置

* * * * * /scripts/script.sh; /scripts/scrit2.sh

13.每年執(zhí)行一次任務(wù)

@yearly /scripts/script.sh

@yearly 類似于“0 0 1 1 *”。它會(huì)在每年的第一分鐘內(nèi)執(zhí)行,通常我們可以用這個(gè)發(fā)送新年的問候。

14.系統(tǒng)重啟時(shí)執(zhí)行

@reboot /scripts/script.sh

總結(jié)

以上是生活随笔為你收集整理的linux启动脚本添加命令,Linux添加shell(.sh)脚本并添加定时任务的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。