how to send a mail with a message in unix script

Rahul sawant picture Rahul sawant · Dec 6, 2013 · Viewed 90.8k times · Source

New to unix and learning the talk and walk of it. I am writing a script in .ksh and have a requirement of sending a mail with a message. Currently using this command in my script:

    mailx -s"File not found" [email protected]

This command helps me having a subject and the recipient name. My question is how can I write a message along with it. Cause every time i run the script it pauses and asks me to enter the message and then executes, I want to pre-include the message so the script would not pause in between.

Answer

user2839978 picture user2839978 · Dec 6, 2013
echo 'Message body goes here' | mail -s 'subject line goes here' [email protected]