使用shell检测raid状态并制作表格发送到邮箱
发布时间:2020-12-15 19:44:42 所属栏目:安全 来源:网络整理
导读:catraid_fzt.sh#!/bin/bash#data:2018.3.9#checkraidstatusandmailtosomeoneDIR="/home/s/ops/pantheon/argos/raid.check"#脚本所在目录cd$DIRLOG='raid_check.2018-03-09_11:17:31'#LOG=$(ls-traid_check.`date+"%F"`.*|xargsecho|cut-d''-f1)BAD_RAID=$(py
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这个文件 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |