Showing posts with label shell script. Show all posts
Showing posts with label shell script. Show all posts

Monday, October 24, 2011

Send mail bash script

Sample Shell Script Here are two samples of shell script to send an email:
1.

#!/bin/bash
# script to send simple email
# email subject
SUBJECT="SET-EMAIL-SUBJECT"
# Email To ?
EMAIL="admin@test.com"
# Email text/message
EMAILMESSAGE="/tmp/body.txt"
echo "This is an email message test"> $EMAILMESSAGE
echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE


2.

#!/bin/sh
while true
do

subject="your-email-bsubject"
mailaddr="admin@example.com"
message=`you-email-body`
encsubject=`echo $subject`

cat << EEE | mail -s "$encsubject" $mailaddr
$encsubject
$message
EEE
exit 0
done

Thursday, January 20, 2011

Shell script for Monitering Mailman process


#----------------------------
# Monitering of mailman process
#----------------------------

unsent=`ls -l /var/spool/mailman/in/ | grep -v grep | grep -c ".pck"`
isAlive=`ps ax | grep -v grep | grep -c "mailmanctl"`
_host=`hostname`
_to=bogati@test.com

if [ $unsent -ne 0 ]; then
/etc/init.d/mailman restart > /dev/null 2>&1

/usr/sbin/sendmail -t <To: $_to
Subject: Mailman has been restarted.

Mailman has been restarted on $_host

EOF

elif [ $isAlive -eq 0 ]; then
        /etc/init.d/mailman start > /dev/null 2>&1

/usr/sbin/sendmail -t <To: $_to
Subject: Mailman has been started.

Mailman has been started on $_host

EOF

fi