LINUX系統延時及定時任務

2021-08-22 00:24:07 字數 2381 閱讀 9392

1系統延時任務

【root@localroot~】# at 23:37  設定任務執行時間

at> rm -fr /mnt/*  任務動作

at>   crtl+d發起任務

【root@localroot~】#at now+1min 延遲1分鐘

at> rm -fr /mnt/*

at>

at -l 檢視任務列表

at -c 任務號  檢視任務內容

at -r 任務號  取消任務執行

注意:當任務有輸出時。輸出會以郵件的形式傳送給at任務的發起者

mail -u root           ##檢視超級使用者郵件

l ##檢視第一封郵件

q ##退出

> /var/spool/mail/root ##清空郵件

###2.at人物的黑白名單

/etc/at.deny                ##系統中預設存在,在此檔案中出現的使用者不能執行at

/etc/at.allow               ##系統中預設不存在,當檔案出現,普通使用者不能執行at

只有在名單中的使用者可以,並且/etc/at.deny失效

###3系統定時任務

1.crontab 時間表示方式

* * * * *             ##每分鐘

*/2 * * * *           ##每兩分鐘

*/2 09-17 * * *       ##早7-晚5每兩分鐘

*/2 */2 * * *         ##每隔2小時每兩分鐘

*/2 09-17 3,5 1 5     ##3月和5月每週周五及3月1日和5月1日

*/2 09-17 * * 5       ##每週周五早九晚五

2.系統控制crontab的服務

crond.service    ##當程式開啟時任務生效

3.crontab

crontab  -e  -u                ##可以編輯使用者crontab內容

crontab -l -u ##列出使用者crontab的內容

crontab -r -u ##刪除使用者crontab的內容

4.檔案方式設定定時任務

vim  /etc/cron.d/file

* * * * *  username  action

* * * * *  root      rm -fr /mnt/*

5.crontab的黑白名單

/etc/cron.deny  系統中預設存在,在此檔案中出現的使用者不能執行crontab

/etc/cron.allow系統中預設不存在,當檔案出現,普通使用者不能執行crontab

只有在名單中的使用者可以,並且/etc/at.deny失效

這2個名單都不會影響/etc/cron.d/目錄中的定時任務的發起及執行

###4系統中臨時檔案的管理方式####

cd  /usr/lib/tmpfiles.d/

vim  westos.conf

d  /mnt/westos  777  root  root  8s

檔案型別  檔名稱  檔案許可權  檔案所有人 檔案所有組 檔案存在時間

systemd-tmpfiles   --creat   /usr/lib/tmpfiles.d/*        ##執行臨時檔案配置

systemd-tmpfiles   --clean   /user/lib/tmpfiles.d/*     ##清理臨時檔案

Linux系統延時任務及定時任務

1.系統延時任務 root localhost at 23.23 設定任務執行時間 at rm rf mnt 任務動作 at ctrl d 用ctrl d發起任務 root localhost at now 1min 延時1分鐘 at l 檢視任務列表 at c 任務號 檢視任務內容 at r 任務...

Linux系統延時任務及定時任務

root client sshd at 02 11 設定任務執行時間 at rm fr mnt 任務動作 job 5 at sun jan 20 02 43 00 2019 用ctrl d發起任務 root client sshd at now 1min 延時1分鐘 at l 檢視任務列表 at c...

linux系統定時任務及延時任務

1 systemctl enable now crond.service 開啟crond服務,系統預設開啟 crontab e 執行 l 檢視內容 r 刪除 e u 指定使用者執行 只有root可以執行 誰寫的crontab檔案名字就是誰 var spool cron root 任務存放位址 2 時...