使用shell检测raid状态并制作表格发送到邮箱

catraid_fzt.sh
#!/bin/bash
#data:2018.3.9
#checkraidstatusandmailtosomeone
DIR="/home/s/ops/pantheon/argos/raid.check"#脚本所在目录
cd$DIR
LOG='raid_check.2018-03-09_11:17:31'
#LOG=$(ls-traid_check.`date+"%F"`.*|xargsecho|cut-d''-f1)
BAD_RAID=$(python/raid.check/marshalv3.py$LOG)#有问题Raid的列表

html_input(){
echo"<tr>
<td>$1</td>
<td>$2</td>
<td>$3</td>
<td>$4</td>
</tr>">>$DIR/mail.html
}#构造一横行表格信息

set_info(){
echo"<head>
<Metahttp-equiv="Content-Type"content="text/html\;charset=UTF-8">
<p><fontcolor="red">如下服务器硬件报警,请业务尽快报修,报修时请在报修工单中写明故障信息。</font></p>
</head>
<tableborder=1>
<tr>
<th>主机信息</th>
<th>Hermes信息</th>
<th>接口负责人</th>
<th>业务负责人</th>
</tr>">$DIR/mail.html
host_list=$(grep$1raid_info|awk'{print$1}')#主机信息列表
forhtml_hostin$host_list
do
html_owner=$(grep$html_hostraid_info|awk'{print$4}')#对应owner信息
html_hermes=$(grep$html_hostraid_info|awk'{print$2}')#对应hermes信息
echo$html_host$html_hermes$1$html_owner
html_input$html_host$html_hermes$1$html_owner#构造每行表格信息
done
echo"</table>
<p><font>如有问题请联系:</font><ahref="mailto:go-sa@mail.net">go-sa@mail.net</a></p>
<p><fontface="arial"color="red">此邮件为系统发送,请勿回复!!!</font></p>">>mail.html
#catmail.html>>all.html#报表汇总
muttmubai@mail.net-s"Raidcheck"-e"setcontent_type=text/html"<$DIR/mail.html#发送邮件
#mutt$1-s"Raid检测报警"-e"setcontent_type=text/html"<$DIR/mail.html
}#制作mail.html,并使用邮件发送

forhostin$BAD_RAID
do
HERMES=$(Pwhoismycluster$host|grep"hermes:"-A1|sed-n'2p'|cut-d:-f1|sed's/[[:space:]]//g')#
OWNER=$(curl-s"http://10.95.22.14:9093/element/findServerUserBy"-H"Content-Type:application/json"-d'{"HostnameIn":"'$host'"}'|grep-Po'"owner":".*?"'|awk-F":"'{print$NF}'|sed's/"//g')
OPS=$(curl-s"http://10.95.22.14:9093/element/findServerUserBy"-H"Content-Type:application/json"-d'{"HostnameIn":"'$host'"}'|grep-Po'"ops":".*?"'|awk-F":"'{print$NF}'|sed's/"//g')
OPS=${OPS:=fanzhengteng@360.net}
HERMES=${HERMES:=没查到HERMES}
OWNER=${OWNER:=没查到OWNER}
#echo$host$HERMES$OPS$OWNER
echo$host$HERMES$OPS$OWNER>>$DIR/raid_info
done#找到hosthermesopsowner信息并写入raid_info这个文件中,供后续处理

OPS_LIST=$(cat$DIR/raid_info|awk'{print$3}'|sort|uniq)#相同邮件人去重
forhtml_opsin$OPS_LIST
do
set_info$html_ops#set_info来发送邮件
done
rm$DIR/raid_info#删除raid_info这个文件

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...