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" abc@def.com
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.
as mailx takes the body as input on stdin you can pipe the body to it:
Or use a here document
If you also want to add attachment to the you want to send. Here you go:
Try this on the command line or inside a script:
You can use pre-defined messages from files:
Alternatively to mailx (mentioned in the other answers) you can also use sendmail:
Perhaps you need to add the full path to sendmail if it's not in your path. E.g. /usr/sbin/sendmail or /usr/lib/sendmail.
Update:
See also this question
Define the mailcontent beforehand and do it like this: