<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                > crontab 用于提交和管理執行周期性的任務。 * 若需要每天凌晨 1 點執行一次任務; * 若每隔1分鐘檢查某服務運行情況; * 若每天定點采集數據; * * * #### crontab 安裝: 一般centos7自帶crontab ###### 1\. 檢測是否安裝 ~~~undefined rpm -qa | grep crontab ~~~ 結果返回如下,說明已安裝 ~~~css crontabs-1.11-6.20121102git.el7.noarch ~~~ 結果為空,執行下面命令進行安裝 ~~~undefined yum install crontabs ~~~ 查看crontab服務是否已設置為開機啟動 ~~~undefined ntsysv ~~~ 加入開機自動啟動 ~~~csharp chkconfig crond on ~~~ #### 2.查看 crontab 運行狀態 ~~~undefined systemctl status crond ~~~ 如果顯示結果為 Active: active (running) 表示運行中 如果顯示結果為 Active: inactive (dead) 表示未運行。 crontab 未運行則通過下面命令設置: crontab 開機自啟: ~~~bash systemctl enable crond ~~~ 啟動 crontab: ~~~undefined systemctl start crond ~~~ 查看當前用戶的定時任務: ~~~undefined crontab -l ~~~ #### 3.設置定時任務 任務:每十分鐘將打印的內容輸入到test.txt文件 編輯腳本任務 ~~~bash cd /root vim /root/test.sh ~~~ 粘貼下面內容 ~~~bash #! /bin/bash echo hello world! >> test.txt ~~~ Esc 鍵,再輸入 :wq 保存文件 執行下面命令即可編輯當前用戶的定時任務: ~~~undefined crontab -e ~~~ 彈出編輯界面,按下 i 進入編輯狀態,粘貼下面內容 ~~~jsx */10 * * * * bash /root/test.sh ~~~ 查看定時任務 ~~~undefined crontab -l ~~~ > \*/10 \* \* \* \* bash /root/test.sh ##### 4.crontab 不執行的原因 * 檢查 crontab 服務是否正常 * 檢查腳本路徑是否絕對路徑 * 檢查腳本路徑前是否添加了 bash 或 /etc/profile;/bin/sh ##### 如果以上都沒問題,那就要通過日志查找問題所在了。 ##### 5.參數說明 \*/10 \* \* \* \* bash /root/test.sh ~~~undefined */10 Minute:每個小時的第幾分鐘執行該任務;取值范圍0-59 * Hour:每天的第幾個小時執行該任務;取值范圍0-23 * Day:每月的第幾天執行該任務;取值范圍1-31 * Month:每年的第幾個月執行該任務;取值范圍1-12 * DayOfWeek:每周的第幾天執行該任務;取值范圍0-6,0表示周末 bash /root/test.sh CommandPath:指定要執行的程序路徑 ~~~ 命令查看 ~~~bash # man crontab ~~~ 整理成表格如下: ![](https://img.kancloud.cn/39/a7/39a739fee3219092cfb1bd9aeba1fe7a_606x285.jpg) ![](https://img.kancloud.cn/0b/20/0b209623e24c052b10709599ac82c840_720x360.jpg) #### 6.舉個栗子 調度示例 ~~~jsx * 1 * * * /opt/script/backup.sh :從1:0到1:59 每隔1分鐘 執行 15 05 * * * /opt/script/backup.sh :05:15 執行 */10 * * * * /opt/script/backup.sh :每隔10分 執行 0 17 * * 1 /opt/script/backup.sh :每周一的 17:00 執行 2 8-20/3 * * * /opt/script/backup.sh 8:02,11:02,14:02,17:02,20:02 執行 ~~~ crontab文件的實例 ~~~csharp 30 21 * * * /etc/init.d/nginx restart # 每晚的21:30重啟 nginx。 45 4 1,10,22 * * /etc/init.d/nginx restart # 每月1、 10、22日的4 : 45重啟nginx。 10 1 * * 6,0 /etc/init.d/nginx restart # 每周六、周日的1 : 10重啟nginx。 0,30 18-23 * * * /etc/init.d/nginx restart # 每天18 : 00至23 : 00之間每隔30分鐘重啟nginx。 0 23 * * 6 /etc/init.d/nginx restart # 每星期六的11 : 00 pm重啟nginx。 * */1 * * * /etc/init.d/nginx restart # 每一小時重啟nginx * 23-7/1 * * * /etc/init.d/nginx restart # 晚上11點到早上7點之間,每 隔一小時重啟nginx 0 11 4 * mon-wed /etc/init.d/nginx restart # 每月的4號與每周一到周三 的11點重啟nginx 0 4 1 jan * /etc/init.d/nginx restart # 一月一號的4點重啟nginx */30 * * * * /usr/sbin/ntpdate 210.72.145.20 //每半小時同步一下時間 ~~~ 作者:是東東 鏈接:https://www.jianshu.com/p/e8e0bc4d5989 來源:簡書 著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看