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?
Problem in using bash/zsh vs /bin/sh
Bash and Zsh have builtin echo with option -e, but a system
/bin/echo
- not. Compare:/bin/echo -e "TO:[email protected] \nSUBJECT:System Booted \n\nBeware I live! \n"
echo -e "TO:[email protected] \nSUBJECT:System Booted \n\nBeware I live! \n"
You may use script like this: