UNIX Programming: Simple Notifications With mailx

Hey there! I know it’s been a month since my last post, I’m sorry about that but I’ve been pretty busy this days, having a lot to do at work and also being a full time student, so anyway, this time I’m sharing with you a nifty tip regarding notifications using mailx on UNIX, so without further ado, here’s the actual code:

#!/bin/ksh
#
# mailx settings:
#
to="someone@somewhere.com"
subject="[Notification] Something happened."
body="Lorem ipsum dolor sit amet et cétera."
#
# run and notify:
#
runSomething && (echo $body | mailx -s "$subject" "$to")

I hope you find it interesting, thanks much for reading and don’t hesitate to leave a comment!

2 Responses to “UNIX Programming: Simple Notifications With mailx”


  1. 1 pete February 27, 2009 at 5:54 pm

    thanks for the knowledge. One question, though: is this service capable of routing mail through an offshore host, like msn, for instance?

    I’m sure there’s a config file somewhere but, after installing mailx, I can’t seem to locate it. I’m running Linux kernel 2.6.23 on an ubuntu distro, btw.

  2. 2 Tom Chamberlain April 7, 2009 at 7:53 pm

    Thanks – great info for a newbie for myself and it worked great after I substituted bash for ksh


Leave a Reply