linux中crontab任務用得很多,但有時候需要在某個時間點執行一下任務就好了,這個時候就需要at任務來了。同時,at任務也可以用來把命令丟到後臺來運行。
at任務使用如下:
1: 假如現在是16:53分,可以使用如下命令把任務丟到後臺執行:
at 23:00
find /var/spool/postfix/maildrop/ -type f|xargs rm
ctrl+D
上面指令加起來表示把find /var/spool/postfix/maildrop/ -type f|xargs rm放到23:00運行。如果遇到Can't open /var/run/atd.pid to signal atd. No atd running?的提示,需要使用:
/etc/init.d/atd restart
用來開啓at任務。
2: 另外,可以使用下列指令查看下at任務的情況。
[root@xxx ~]# atq
2 2017-02-26 23:00 a root
atq可以查看有多少個at任務待執行。
[root@xxx ~]# at -c 2
....忽略輸出
${SHELL:-/bin/sh} << 'marcinDELIMITER3a67af1b'
find /var/spool/postfix/maildrop/ -type f|xargs rm
at -c 序號可以查看at任務的詳細信息。
3: 刪除at任務
[root@xxx ~]# atq
2 2017-02-26 23:00 a root
[root@xxx ~]# atrm 2
[root@xxx ~]# atq
[root@xxx ~]#
使用atrm可以刪除at任務。
最後附上本人的網絡課堂地址,如有興趣請點擊: 實踐哥