主题和领域都不顺利

时间:2013-04-30 10:31:12

标签: linux shell ubuntu

我创建了一个shell脚本,用于检查mysql的状态,如果没有运行则发送邮件。脚本运行良好,但邮件中的主题并不好。

FROM_ADDRESS即将root,主题即将来临blank

#!/bin/bash
TO_ADDRESS="abdul@gmail.com"
FROM_ADDRESS="StatusUpdate"
SUBJECT="MySQL Server Status Update"
SENT_DATE=`date`

# This file will hold all the contents that needed to be sent in mail.
BODY_FILE="contents.log"
COMMAND=`which sendmail`
CC_LIST="navodaya05@gmail.com"

# Remove the file if exists
rm $BODY_FILE

echo "Hi All"$'\n' >> $BODY_FILE
echo "This is MySQL Server status update.Status Checked At $SENT_DATE." >> $BODY_FILE

# The below line will check status for mysql if it is running it wil return output  "mysqlstart/running,"
SERVER_STATUS_TO_CHECK=`service mysql status | grep 'mysql' | awk '{print $1 $2}'`

# Check status and if server is not running and send mail
if [ "$SERVER_STATUS_TO_CHECK" == "mysqlstart/running," ]; then
    echo "MySQL is Running"$'\n'>> $BODY_FILE
else
    echo "MySQL Server is not running.Please investigate ASAP."$'\n' >> $BODY_FILE
    echo "Best Regards" >> $BODY_FILE
    echo "Admin" >> $BODY_FILE
    $COMMAND -s "${SUBJECT}" -c ${CC_LIST} ${TO_ADDRESS} -- -r ${FROM_ADDRESS} < ${BODY_FILE}
fi

1 个答案:

答案 0 :(得分:1)

我认为问题可能在于以这种方式使用sendmail。或许邮寄是更好的选择

http://unixhelp.ed.ac.uk/CGI/man-cgi?mail

http://unixhelp.ed.ac.uk/CGI/man-cgi?sendmail