Bash - Sending E-Mail From The Command Line

This guide outlines the requirements to send e-mail from the bash command line on Gentoo Linux but the instructions are mostly the same for Red Hat Enterprise Linux, OpenSUSE, Debian, Ubuntu or Slackware. Just replace emerge by your distro's package manager of choice, like yum, zypper or apt-get commands.

First, install the "mail-client/mailx" package by using emerge, as root:

emerge mail-client/mailx

echo "Hello World!" | mail -s Subject destination@mailserver.com

This assumes you already have "postfix" installed and configured, which you can check how to do here:

emerge postfix
/etc/init.d/postfix start

The test e-mail should arrive to your destination e-mail box of choice. Script away using the command to send e-mails in batch or to warn the sysadmin of problems in the box.

No comments:

Post a Comment