Piping echo into sendmail in rc.local fails

255 views Asked by At

I'm trying to get my system to send me an email when the system boots. Using the following command works as intended:

echo -e "TO:[email protected] \nSUBJECT:System Booted \n\nBeware I live! \n"$1 | sendmail -t -vs

But if I add it to rc.local like so:

#!/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

I get:

sendmail: No recipients specified although -t option used

Why is this failing?

1

There are 1 answers

0
rominokun On BEST ANSWER

Problem in using bash/zsh vs /bin/sh

Bash and Zsh have builtin echo with option -e, but a system /bin/echo - not. Compare:

You may use script like this:

#!/bin/sh
sendmail -t -vs <<EOF
TO:[email protected]
SUBJECT:System Booted

Beware I live!
$1
EOF