I have tried a few things so far but with no success.

I modified crontab and and preceeded the command with @reboot mail.mailutils ...

I also created a .sh script, changed permission, added it to init.d modified configuration with sysv-rc-config --level 3 script on and added the necessary line to rc.local.

I would really appreciate if you could tell me where else to look!

I just want to send an email when I boot my Ubuntu (desktop not server) and when I turn it off.

The script that I am using is not even a script is

mail.mailutils -s "subject" emailaddress <<< "message" 
  • Add your script to the question so others might see why it's not working. – WinEunuuchs2Unix Feb 4 '18 at 4:12

First, check if you can send email. I am using mailutils to send email, the way to send email is:

    echo "system start" | mail -s "start" youraccount@xx.com

Second, add a systemd task to listening the boot and shutdown event.

  1. create a file /etc/init.d/myemail, then add the following scripts.
  2. sudo update-rc.d myemail defaults
  3. now its done.
  4. Tips: some email provider will intercept your email, since your email account is not like a common email format.

    #! /bin/sh
    # Provides:          myemail
    # Required-Start: 
    # Required-Stop:
    # Default-Start:     1 2 3 4 5
    # Default-Stop:      0 6
    # Short-Description: on boot and shutdown send a email.
    # Description:
    . /lib/lsb/init-functions
    case "$1" in
            echo "system start" | mail -s "start" youraccount@xx.com
            date +"%Y-%m-%d %H:%M:%S   --start" >> /var/log/myemail.log
            echo "Error: argument '$1' not supported" >&2
            exit 3
            echo "system poweroff" | mail -s "poweroff" youraccount@xx.com
            date +"%Y-%m-%d %H:%M:%S   --stop" >> /var/log/myemail.log
            echo "Usage: $0 start|stop" >&2
            exit 3
    return 0
  • Hey! I get an error when I try the second command: update-rc.d: error: initscript does not exist: /etc/init.d/myemail – Alex Feb 13 '18 at 21:52
  • I have tell you at first step, create a file /etc/init.d/myemail. It means create a file named myemail in the directory '/etc/init.d'. Then add the scripts content from ahead to the file myemail. Check your steps. – Y.Elva Feb 25 '18 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.