我正试图让我的系统在系统启动时向我发送电子邮件。使用以下命令按预期工作:
echo -e "TO:my-email-address@gmail.com \nSUBJECT:System Booted \n\nBeware I live! \n"$1 | sendmail -t -vs
但是如果我把它像这样添加到rc.local:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
#----- Print the IP address
#_IP=$(hostname -I) || true
#if [ "$_IP" ]; then
# printf "My IP address is %s\n" "$_IP"
#fi
#----- Notify on boot
/home/alex/notify/boot.sh "`date`"
exit 0
我明白了:
sendmail: No recipients specified although -t option used
为什么会失败?
答案 0 :(得分:0)
使用bash / zsh vs / bin / sh
时出现问题 Bash和Zsh内置了echo选项-e,但是系统/bin/echo
- 没有。
比较:
/bin/echo -e "TO:my-email-address@gmail.com \nSUBJECT:System Booted \n\nBeware I live! \n"
echo -e "TO:my-email-address@gmail.com \nSUBJECT:System Booted \n\nBeware I live! \n"
您可以使用以下脚本:
#!/bin/sh
sendmail -t -vs <<EOF
TO:my-email-address@gmail.com
SUBJECT:System Booted
Beware I live!
$1
EOF