1

I want to send a mail to myself at the restart of a server. We use AWS, and a restart results in a changed internal 10.x.x.x address. This address has to be configured in Postgres and elsewhere, and this would be a nice reminder.

I found this solution, but when trying it I get the error that mail is not installed. Sendmail/postfix is installed.

@reboot  echo "Server has restarted "`hostname` | mail -s "System Restart" example@example.com

Do I need to install mail-utils or can I do without using another solution?

1

The error simply means that the mail package is not installed or the mail script is not present on the system.

To resolve the issue, install the mailx or mailutils package depending on your distro.

As you have tagged CentOS in the question, so you need to install the mailx package.

$ sudo yum install mailx

Mailx is an enhanced mail command, which provides the functionality of the POSIX mailx command, as well as SysV mail and Berkeley Mail from which it is derived. Whereas, Mailutils provides a set of useful mail libraries, daemons, clients and servers for delivering and reading electronic mail.

Mailx is available for RHEL, CentOS, Scientific Linux or their variants. Whereas, Mailutils provides a set of useful mail libraries, daemons, clients and servers for delivering and reading electronic mail. Mailutils is available in Debian, Ubuntu or their variants.

Check this link for more info about it.

1

On Debian/Ubuntu you need bsd-mailx package installed to send emails.

Where did you added the above command? There are 3 possible reasons the mails aren't send:

  • this command isn't executed at all (add it to /etc/rc.local to make sure it will be executed)
  • bsd-mailx package isn't installed
  • you tried to install some MTA which broke bsd-mailx configuration
1

You can use sendmail directly to send the email.
Using custom shell script would make it "cleaner".

  • make crontab execute custom script

    @reboot .../reboot-notify

  • make the script use sendmail directly

simple script (e.g. you can make it check that IP address has changed)

#!/bin/sh
HOSTNAME=`hostname`    

/usr/sbin/sendmail -i example@example.com <<END
Subject: System restart

Server has restarted: $HOSTNAME
END

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.