sendmail使用案例1
查询hive数据后发邮件给开发人员
#!/bin/bash
css_type='
<style type="text/css">
table.gridtable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table.gridtable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
</style>
'
ct_date=`date +%Y-%m-%d`
result_dir="/tmp/ods/$ct_date"
mkdir -p $result_dir
# yesterday=`date +"%Y%m%d" -d "-1 days"`
echo " " > $result_dir/resutl_ods_01_member.txt
echo "$css_type" >> $result_dir/resutl_ods_01_member.txt
echo "<h3>$ct_date 会员异常信息一览表 </h3>" >> $result_dir/resutl_ods_01_member.txt
echo "<table class=\"gridtable\">" >> $result_dir/resutl_ods_01_member.txt
echo "<tr><td>异常信息描述</td><td>数量</td></tr>" >> $result_dir/resutl_ods_01_member.txt
hive -e "select extends['ERR_MESSAGE'],count(*) from ods.ods_member where data_invalid_type = 'ERROR' group by extends['ERR_MESSAGE']" | sed '/WARN:.*/ d' | awk -F " " '{print "<tr>" "<td>" $1 "</td>" , "<td>" $2 "</td>" "</tr>"}' >> $result_dir/resutl_ods_01_member.txt
echo "</table>" >> $result_dir/resutl_ods_01_member.txt
receiver_list="user1@163.com,user2@163.com"
send_user_email="admin@mail.qq.com"
send_user_password="123456"
send_user_smtp="smtp.exmail.qq.com:587"
email_title="ods_member exception $ct_date"
# email_title要转utf-8 https://www.base64encode.org/
cat $result_dir/resutl_ods_01_member.txt | sendEmail -f $send_user_email -t $receiver_list -o tls=yes -s $send_user_smtp -u $email_title -xu $send_user_email -xp $send_user_password -o message-content-type=html -o message-charset=utf8
邮件预览
image
网友评论