Simple Mailx script

Posted on 2007-12-03
Last Modified: 2013-12-27
Hi I'm looking for a very simple 2 - 3 line mailx script to send a one line message to my email address. I need this to test setting up some jobs in a scheduler program.
Question by:7Souls
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 38

Accepted Solution

yuzh earned 250 total points
ID: 20400090
You can do:

echo "my messgae" | /usr/bin/mailx -s "My Subject" you@soemwhere
# End of script

or mail a text file

/usr/bin/mailx -s "My Subject" you@soemwhere </path-to/mymessage.txt
# End of script

man mailx
to learn more details
LVL 40

Expert Comment

ID: 20400516

If you are going to use it in crontab:

0 3 * * * /pat/to/myscript 2> &1 | mailx -s "script results" me@mydomain
LVL 40

Expert Comment

ID: 20400521

I am repeating since there shouldn't be a space

0 3 * * * /pat/to/myscript 2>&1 | mailx -s "script results" me@mydomain

Author Closing Comment

ID: 31412472
Thanks yuzh, in addition I had to change some permissions but it ran perfectly in Contol -M.


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
FreeBSD on EC2 FreeBSD ( is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question