linux下系統延時任務及定時任務
##1.系統延時任務##
at 23:37 ##設定任務執行時間
at> rm -fr /mnt/* ##任務動作
at> <EOT> << CTRL+D ##執行動作
at now+1min ##延時1分鐘
at> rm -fr /mnt/*
at> <EOT>
at -l ##檢視任務列表
at -c 任務號 ##檢視任務內容
at -r 任務號 ##取消任務內容
注意:
當任務有輸出時,輸出會以郵件的形式傳送給使用者
mail -u root ##檢視超級使用者郵件
1 ##檢視第一封郵件
q ##退出
> /var/mail/root ##清空郵件
##2.at任務的黑白名單##
/etc/at.deny ##系統中預設存在,在此檔案中出現的使用者不能執行at
/etc/at.allow ##系統中預設不存在,當檔案出出現,普通使用者不能執行at
##當/etc/at.allow檔案存在,/etc/at.deny檔案失效
##3.系統定時任務##
1.crontab 時間表示方式
* * * * * ##每分鐘
*/2 * * * * ##每2分鐘
*/2 9-17 * * * ##早上九點到下午五點每兩分鐘
*/2 */2 * * * ##每隔兩小時每兩分鐘
*/2 9-17 3,5 1 5 #3月和5月每週週五及3月1日和5月1日早九晚五每兩分鐘
*/2 9-17 * * 5 ##每週五早九晚五每兩分鐘
2.系統crontab的服務
crond.service ##當程式開啟時定時任務生效
3.crontab
crontab -e -u ##編輯
crontab -l -u ##檢視
crontab -r -u ##清除
4.檔案方式設定當時任務
vim /etc/cron.d/file
* * * * * uesrname action
* * * * * root rm -fr /mnt/*
5.crontab的黑名單
/etc/cron.deny ##系統中預設存在,在此檔案中出現的使用者不能執行crontab
/etc/cron.allow ##系統中預設不存在,當檔案出出現,普通使用者不能執行crontab
##只有在名單中的使用者可以,並且/etc/cron.deny失效
##這兩個名單都不會影響/etc/cron.d/目錄中定時任務的發起及執行
###4.系統中臨時檔案的管理方式###
cd /usr/lib/tmpfiles.d/
vim westos.conf
檔案型別 路徑 許可權 所有人 所有組 壽命
d /mnt/westos 777 root root 8s
root
systemd-tpmfiles --create /usr/lib/tmpfiles.d/*
systemd-tpmfiles --clean /usr/lib/tmpfiles.d/*