当作业在Linux系统上运行时,显示器并不会关联到该作业。取而代之的是,Linux系统会将提交该作业的用户的电子邮件地址作为STDOUT和STDERR。任何发到STDOUT或STDERR的输出都会通过邮件系统发送给该用户。
这里有个在CentOS发行版中使用at命令安排作业执行的例子。
$ cat test13.sh
#!/bin/bash
# Test using at command
#
echo "This script ran at $(date +%B%d,%T)"
echo
sleep 5
echo "This is the script's end..."
#
$ at -f test13.sh now
job 7 at 2015-07-14 12:38
$
at命令会显示分配给作业的作业号以及为作业安排的运行时间。-f选项指明使用哪个脚本文件,now指示at命令立刻执行该脚本。
使用e-mail作为at命令的输出极其不便。at命令利用sendmail应用程序来发送邮件。如果系统中没有安装sendmail,那就无法获得任何输出!因此在使用at命令时,最好在脚本中对STDOUT和STDERR进行重定向,如下例所示。
$ cat test13b.sh
#!/bin/bash
# Test using at command
#
echo "This script ran at $(date +%B%d,%T)" > test13b.out
echo >> test13b.out
sleep 5
echo "This is the script's end..." >> test13b.out
#
$
$ at -M -f test13b.sh now
job 8 at 2015-07-14 12:48
$
$ cat test13b.out
This script ran at July14,12:48:18
This is the script's end...
$
如果不想在at命令中使用邮件或重定向,最好加上-M选项来屏蔽作业产生的输出信息。