Tuesday, 4 March 2014

SHELL SCRIPT TIPS: mailx function in linux

As linux server administrators we may have to send mails via command line. Especially, while writing a shell script to monitor something in server ( example load) and send out mails, mailx play an important role in this scenario.

Lets see how to install mailx function in a linux machine:
root@newserver [~]# yum list | grep mailx
mailx.x86_64                               12.4-7.el6                  base

The above command will show the available mailx package.

Use yum install to install mailx as below:
yum install mailx

Now, if you want to see the binary:
 root@newserver [~]# which mailx
root@newserver [~]#

So, if you roll out a script to many servers to send out mails using puppet, then it is always good to state a condition in your shells script as follows:

if [ ! -f /bin/mailx ]; then
  echo "installing mailx";
  yum install mailx

The above condition will install mailx, if it does not exist.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.