Press "Enter" to skip to content

Shell之at命令(一定性定时计划任务)

at跟crontab一样,都是执行定时计划任务的命令。但不同的是,crontab执行的循环的任务,而at执行的是一次性任务,任务执行完以后便失效。

设置任务:

at now + 1 week -f a.sh      #a.sh必须已存在

at 01:35 < my-at-jobs.txt    
at < my.txt 01:35            #也可以把时间写在后面

at now +2 minutes <<< "mkdir 123"

at now +10 minutes <<ENDMARKER
rm -rf 123
echo successful done > /var/log/messages
ENDMARKER

查看所有任务:

at -l
atq

查看单个任务:

at -c ID

删除任务:

atrm 23
at -r 1

关于时间,可参考的语法:

noon	        12:00 PM October 18 2014
midnight	12:00 AM October 19 2014
teatime	        4:00 PM October 18 2014
tomorrow	10:00 AM October 19 2014
noon tomorrow	12:00 PM October 19 2014
next week	10:00 AM October 25 2014
next monday	10:00 AM October 24 2014
fri	        10:00 AM October 21 2014
NOV	        10:00 AM November 18 2014
9:00 AM	        9:00 AM October 19 2014
2:30 PM	        2:30 PM October 18 2014
1430	        2:30 PM October 18 2014
2:30 PM tomorrow	2:30 PM October 19 2014
2:30 PM next month	2:30 PM November 18 2014
2:30 PM Fri	        2:30 PM October 21 2014
2:30 PM 10/21	        2:30 PM October 21 2014
2:30 PM Oct 21	        2:30 PM October 21 2014
2:30 PM 10/21/2014	2:30 PM October 21 2014
2:30 PM 21.10.14	2:30 PM October 21 2014
now + 30 minutes	10:30 AM October 18 2014
now + 1 hour	11:00 AM October 18 2014
now + 2 days	10:00 AM October 20 2014
4 PM + 2 days	4:00 PM October 20 2014
now + 3 weeks	10:00 AM November 8 2014
now + 4 months	10:00 AM February 18 2015
now + 5 years	10:00 AM October 18 2019
Leave a Reply

Your email address will not be published. Required fields are marked *