Linux/AIX/HP-UNIX监控磁盘脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux/AIX/HP-UNIX监控磁盘脚本相关的知识,希望对你有一定的参考价值。

#!/bin/sh

os_ver=`uname`


if [ "$os_ver" = "Linux" ]; then

#line_num=`df -h|grep -v Filesystem|grep -v proc|awk ' gsub(/%/,"",$5) {print $6 "   " $5}' |wc -l`

line_num=`df -h|grep -v Filesystem|grep -v proc |grep   '[[:digit:]]' | awk '  gsub(/%/,"",$(NF-1)){print $NF,$(NF-1)}' |wc -l`

i=0

echo "["

df -h|grep -v Filesystem|grep -v proc |grep   '[[:digit:]]' | awk '  gsub(/%/,"",$(NF-1)){print $NF,$(NF-1)}'|while read v_file v_precent

#df -h|grep -v Filesystem|grep -v proc|awk ' gsub(/%/,"",$5) {print $6 "   " $5}'|while read v_file v_precent

do

 let i=i+1

 if [ $i -lt $line_num ]; then

    echo  "{"v_file":"$v_file","v_precent":"$v_precent"},"

 else

    echo  "{"v_file":"$v_file","v_precent":"$v_precent"}"

 fi

done

echo "]"


elif [ "$os_ver" = "AIX" ]; then

i=0

line_num=`df -g|grep -v Filesystem|grep -v proc|awk ' gsub(/%/,"",$4) {print $7 "   " $4}' |wc -l`

echo "["

df -g|grep -v Filesystem|grep -v proc|awk ' gsub(/%/,"",$4) {print $7 "   " $4}'|while read v_file v_precent

do

 let i=i+1

 if [ $i -lt $line_num ]; then

    echo  "{"v_file":"$v_file","v_precent":"$v_precent"},"

 else

    echo  "{"v_file":"$v_file","v_precent":"$v_precent"}"

 fi

done

echo "]"


else

line_num=`bdf |grep -v Filesystem|grep '[[:digit:]]'  |awk 'gsub(/%/,"",$(NF-1)) {print $NF,$(NF-1)}' |wc -l`

#line_num=`bdf |grep -v Filesystem|awk ' gsub(/%/,"",$5) {print $6 "   " $5}' |wc -l`

i=0

echo "["

bdf |grep -v Filesystem|grep '[[:digit:]]'  |awk 'gsub(/%/,"",$(NF-1)) {print $NF,$(NF-1)}'|while read v_file v_precent

#bdf |grep -v Filesystem|awk ' gsub(/%/,"",$5) {print $6 "   " $5}'|while read v_file v_precent

do

 let i=i+1

 if [ $i -lt $line_num ]; then

    echo  "{"v_file":"$v_file","v_precent":"$v_precent"},"

 else

    echo  "{"v_file":"$v_file","v_precent":"$v_precent"}"

 fi

done

echo "]"

fi


以上是关于Linux/AIX/HP-UNIX监控磁盘脚本的主要内容,如果未能解决你的问题,请参考以下文章

sh 如果HP SmartArray磁盘出现问题,此脚本将发送错误电子邮件

Python磁盘监控日志分析监控脚本

Linux/Unix shell 脚本监控磁盘可用空间

Linux之Shell脚本实战监控系统的磁盘空间使用率

树莓派CPUGPU磁盘内存负载监控Python脚本

Linux下磁盘监控脚本