使用shell批量監控磁碟壞塊 二

2021-09-22 19:10:25 字數 4657 閱讀 3613

之前分享了第一篇 使用shell批量監控磁碟壞塊(一),今天來簡單說說這個需求的實現內容 。

首先主要思路是通過中控的機器來傳送監控的細節,然後返回結果。

首先就是我們需要有乙個伺服器列表,裡面會有這些需要的元資料資訊。

比如列表如下:

192.127.133.13   某某服務中心主庫           jeanron   primary linux   oracle  n    ***

192.127.133.12   某某服務備庫           jeanron  standby linux   oracle  n   ***x

192.127.133.18   某某業務主庫   jeanron  primary linux   oracle  n       ***x

192.127.133.52   某某業務備庫  jeanron  primary linux   oracle  n       ***x

通過這個列表就可以開始分析了。指令碼實現內容如下:

. ~/.bash_profile > /dev/null

basedir="/home/hardcheck"

mkdir -p $/ && cd $

date=`date +%y%m%d%h%m`

log="hardcheck_$.log"

tmp_script="hardcheck_$.sh"

exec 3>&1 4>&2 1>$log 2>&1

### 將伺服器列表作為引數傳遞進來,為了考慮字元相容性,統一採用utf8來處理

serverlist=$1

if [ -z "$" ] || [ ! -s "$" ] ; then

cat /home/jeanron/alldbserver-linux.txt|iconv -f gbk -t utf8|grep jeanron|grep -v solaris|grep -v nopingdb|grep -v "#1"> db_list.all.lst

serverlist=$basedir/db_list.all.lst fi

ssh="ssh -oconnectionattempts=3 -oconnecttimeout=5 -ostricthostkeychecking=no"

echo "#start hardcheck"

### '`

db=`echo $tmp_host|awk ''`

owner=`echo $tmp_host|awk ''`

std_type=`echo $tmp_host|awk ''`

db_type=`echo $tmp_host|awk ''`

ilo_info=`echo $tmp_host|awk ''`

echo "echo \"$ip;$db;$owner;$std_type;$db_type;$ilo_info\"" >> $tmp_script

echo "$ $ip \"/opt/megaraid/megacli/megacli64 -cfgdsply -a0|grep error;/opt/megaraid/megacli/megacli64 -pdlist -aall|grep firmware|grep -v level|grep -v up|grep -v  online \" " >>$tmp_script

done < $

### }}}

### -s "disk error count health daily check($)" $/mail.txt

裡面有幾個地方可以改進一下,對於命令的報告形式,發現還是有乙個指令碼非常不錯,beautymail.sh

內容如下,對於格式美化還是非常給力的,我們只需要輸入乙個基本格式的資料,就會輸出乙個格式化後的結果內容,非常給力。

輸出的結果類似下面的效果。

指令碼內容如下,當然也是參考了很多的出處,我只是引用一下。

source /etc/profile > /dev/null

. ~/.bash_profile > /dev/null

title=''

topline=""

html='/tmp/info.html'

mail='[email protected]'

subject='【報警輸出優化】test'

while getopts "a:t:t:h:m:s:h" option do

case $option in

a) addfile="$optarg";;

t) title="$optarg";;

t) topline="$optarg";;

h) html="$optarg";;

m) mail="$optarg";;

s) subject="$optarg";;

h) usage: beautymail [-a addfile] [-t title-in-mail] [-t topline] [-h html-location] [-m mail-addr] [-s subject] content-file\n\

options:

-a:     設定郵件裡加附件,addfile需要附件的絕對路徑

-t:     設定郵件裡**上方的說明文字

-t:     設定**中首行,即各列的含義,如-t \" 日誌型別;日誌量;檔案數 \", 注意是用英文分號隔開的多列

-m:     指定收件人

-s:     郵件主題 "

exit

esac

done

shift $(($optind - 1))

function init()

eoftopline=$(echo $topline |sed -e 's/^//' -e 's/;/;/g' -e 's/$//')

write2table "$topline" yellow }

function write2table() }')

#       for colume in $line;do

echo "$1"|awk -f';' '}'|while read colume do

wcl=$(cat $html|wc -l)

insert=$(echo $-1|bc)

#                echo $insert $colume

#                echo

if [ -n $2 ] ; then

sed -i "$insert i\ $colume" $html

else

sed -i "$insert i\ $colume" $html fi

done }

init

[ -z $1 ] && echo 'at least need a log file to mail' && exit 2

cp -p $1 $1.tmp

dos2unix $1.tmp # && sed -i -e 's/ /;/g' -e 's/\t/;/g' $1

#for i in $(cat $1);do

### 按行處理

cat $1.tmp |while read line do

write2table "$line"

done

rm -f $.tmp

#傳送帶附件的html格式正文的函式 (對於非txt或者cvs格式的檔案,例如excel的xls,需要單獨修改type:搜mimetype)

#$1: mail_from

#$2: mail_to

#$3: subject

#$4: content mimetype, such as "text/plain"

#$5: content

#$6: attach mimetype, such as "text/csv"

#$7: attach display name

#$8: attach file path

function sendmail**********attach()

##! @todo: 傳送郵件

##! @author:

##! @version: 1.0

##! @in:

##! @out:

function sendmail() ')

sendmail**********attach "$from" "$to" "$subject" "$content_type" "$body" "$attach_type" "$attach_name" "$attach_path"

echo "send mail done." }

echo $addfile

if [ -z "$addfile" ];then

sendmail "$mail" "$subject" "$html"

else

sendmail "$mail" "$subject" "$html" "$addfile" fi

#mutt -e 'my_hdr content-type: text/html' "$mail" -s "$subject" < "$html";

Shell之批量監控主機磁碟使用率

1 本地磁碟監控 use rate list df h awk dev 結果 dev sda1 10 for use rate in use rate list do part name use rate if use rate ge 80 then echo warning part name p...

zabbix應用之監控磁碟壞塊 windows

za bbix 支援對windows事件日誌的監控。利用zabbix監控,在事件日誌 現磁碟錯誤時,zabbix及時發出告警資訊。一 事件檢視器 事件檢視器是windows系統提供的乙個系統安全監視工具。在硬體 軟體或者系統出現問題的時候,利用事件檢視器,可以方便的對故障資訊進行分析 查詢具體原因。...

監控磁碟使用率的shell指令碼

本指令碼來自有學習阿銘的博文學習 公司監控最基本的一般都要監控磁碟的使用情況,否則將導致業務上的事故。一般監控要求如下 每分鐘都要掃瞄一下磁碟的狀況。當磁碟空間使用率或者inode使用率高於90 的情況,就需要報警。並把統計使用率超過90 的分割槽的所有的子目錄的,按照大小依次排列,把前3的目錄名稱...