Linux計畫任務管理

2022-06-30 12:27:11 字數 2867 閱讀 7545

前提:  atd服務必須執行

[root@wei init.d]# yum -y install at        #安裝atd服務

[root@wei init.d]# systemctl start atd      #開啟atd服務

[root@wei init.d]# systemctl status atd     #檢視atd開啟狀態

18:00關機(以系統時間為準):

[root@wei init.d]# at 18:00

at> poweroff

at> # ctrl+d 提交任務

job 1 at fri feb  1 18:00:00 2019

1分鐘後執行的任務:

[root@wei init.d]# at now + 1 minute

at> mkdir /root/nangong

at> job 4 at thu jan 31 18:49:00 2019

前提:crond服務必須執行

[root@wei ~]# yum install crontabs      #安裝crond服務

[root@wei init.d]# systemctl start crond      #開啟crond服務

[root@wei ~]# systemctl status crond       #檢視crond開啟狀態

製作週期性計畫任務

# crontab -e時間        command每天晚上11:30     30 23 * * *

每天零點          0 0 * * *    

每天早上8:10 9:10 10:10   10 8-10 * * *  

每隔5分鐘          */5 * * * *

每隔3小時          * */3 * * *

command命令:

1.建議寫命令的完整路徑 /bin/mkdir/abc

2.只能寫一條命令(shell)

建立計畫任務

示例:

(1)每分鐘在tmp目錄下建立檔案

(2)每分鐘分別顯示磁碟使用,cpu狀態,記憶體狀態的資訊

分析:一行只能寫一條命令,但要顯示三個命令,則需要借助shell指令碼。然後在週期性任務中呼叫shell指令碼。

(1)建立shell指令碼

[root@wei ~]# vim hei.sh

#!/bin/bash

echo

echo "cpu負載"

uptime

echo

echo "磁碟容量:"

df -ht

echo

echo "記憶體容量"

free -h

我在次呼叫演示。

(2)建立週期性任務

[root@wei ~]# crontab -e     

*/1 * * * *  /usr/bin/bash /root/hei.sh

注意:這個會給root使用者發郵件顯示shell指令碼執行的資訊

*/1 * * * *  /usr/bin/bash /root/hei.sh &> /dev/null
&> /dev/null  不給使用者發郵件檢視計畫任務

[root@wei ~]# crontab -l

*/1 * * * *   /usr/bin/touch /tmp/wei/$(date +\%f-\%t).txt

*/1 * * * *  /usr/bin/bash /root/hei.sh &> /dev/null

刪除計畫任務(全部刪除)

[root@wei ~]# crontab -r

Linux 計畫任務管理crontab at

1.crontab 命令 按照預先設定的時間週期 分鐘 小時 天 重複執行使用者指定的命令操作,屬於週期性計畫任務,預設開啟 var spool cron 使用者 檔案 服務指令碼名稱 etc init.d crond 主要設定檔案 全域性配置檔案,位於檔案 etc crontab 系統預設的設定,...

linux計畫任務的管理

2.一次性計畫任務 at 1 了解at rpm qf which at 檢視屬於哪個軟體包 rpm ql at 檢視at程式安裝的所有軟體 etc 配置檔案 bin 或者 usr sbin 命令 etc rc.d init.d 啟動指令碼 usr share doc 幫助和說明文件 var spoo...

Linux程序計畫任務管理

二 定時任務 ps命令 檢視系統程序命令 ps aux主要檢視程序所占用cpu及記憶體的百分比 ps leftop命令 動態查詢程序的情況 pgrep命令 根據特定條件查詢程序pid資訊 l 顯示程序名 u 指定特定使用者ctrl z 將當前程序掛起,即調入後台並停止執行 jobs 檢視處於後台的任...