例如,可以试试创建一个未来几分钟的任务,来给自己计划一个备忘录。这里运行一个简单的任务,以减少失败的可能性。要退出 at提示符,请按键盘上的Ctrl+D。
$ at 11:20 AMwarning: commands will be executed using /bin/shat> echo "hello world" > ~/at-test.txtat>
正如你所看到的,at使用直观和自然的时间定义。你不需要用 24 小时制的时钟,也不需要把时间翻译成 UTC 或特定的 ISO 格式。一般来说,你可以使用你自然想到的任何符号,如noon、1:30 PM、13:37等等,来描述你希望一个任务发生的时间。
等待几分钟,然后在你创建的文件上运行 cat或者tac命令,验证你的任务是否已经运行:
$ cat ~/at-test.txthello world
用 at 安排一个任务
你不必使用 at交互式提示符来安排任务。你可以使用echo或printf向它传送命令。在这个例子中,我使用了now符号,以及我希望任务从现在开始延迟多少分钟:
$ echo "echo 'hello again' >> ~/at-test.txt" | at now +1 minute
一分钟后,验证新的命令是否已被执行:
$ cat ~/at-test.txthello worldhello again
这些是一些有效表达式的例子:
$ echo "rsync -av /home/tux me@myserver:/home/tux/" | at 3:30 AM tomorrow$ echo "/opt/batch.sh ~/Pictures" | at 3:30 AM 08/01/2022$ echo "echo hello" | at now + 3 days