Posts Tagged ‘shell’

Send mail bash script

Mail is the command in UNIX bash shell to send email from that machine to one or more recipient. Mail can be invoked with arguments which are the recipients. This is followed by your message and ‘ctrl-D’ at the start of the line. The simple way to send a mail from unix is:

mail -s ‘Mail Subject’ You@sdexperts.com

Example Shell Script to send Mail.

Use the below sample shell script:

# Shell script to send email
#!/bin/bash

# Email Subject
SUB=”Email Subject”

# Email Recipient
EMAIL=”You@sdexperts.com”

# Email text/message
echo “Hey – How is it going”> $EMAIL-MESSAGE
echo “Send mail bash Shell script works fine” >>$EMAIL-MESSAGE

# send email using /bin/mail

/bin/mail -s “$SUB” “$EMAIL” < $EMAIL-MESSAGE

Steps for dummies:
Go to the dir you want to have this shell script.
vi sendMail.sh (create shell script)
Paste the above code.
:wq (Save the shell)
chmod 755 sendMail.sh (Give permission to the script)
./sendMail.sh (Run the script)

1 comment - What do you think?  Posted by admin - March 16, 2011 at 1:48 pm

Categories: Tech Support   Tags: , , , ,