
從 at/batch 的手冊頁來看,它說
The user will be mailed standard error and standard output from his
commands, if any. Mail will be sent using the command /usr/sbin/sendmail.
If at is executed from a su(1) shell, the owner of the login shell will
receive the mail.
但是如何配置發送到哪個電子郵件地址呢?
在 cron 中可以使用 MAILTO 環境變量,但在at
或中的任何地方都看不到它batch
。
答案1
我沒有看到在 at 呼叫中執行此操作的方法,但您可能可以使用透過 at 呼叫的命令執行類似的操作:
$ at 16:00
at> some-command [arguments, &c.] 2>&1 | sendmail [-f <from-address>] <recipient>
at> ^D
當該命令運行時,它會將其輸出傳遞給 sendmail 以發送給指定的收件人,並且在我剛剛運行的快速測試中,這確實有效。
當然,如果您已經將某個命令的輸出重定向到其他地方,那麼您可能會運氣不佳 - 但是,您始終可以 tee(1) 輸出,或者在 at 中添加最後一行調用sendmail 來推送訊息的作業。