1. 程式人生 > 其它 >linux磁碟未掛載檢測

linux磁碟未掛載檢測

#!/bin/sh
#獲取當前機器磁碟

#作業系統版本號
if grep -q 'CentOS.*.release 6.*\.' /etc/redhat-release; then
os_release=el6
elif grep -q 'CentOS.*.release 7.*\.' /etc/redhat-release; then
os_release=el7
elif grep -q 'Red Hat.*.release 6.*\.' /etc/redhat-release; then
os_release=el6
elif grep -q 'Red Hat.*.release 7.*\.' /etc/redhat-release; then
os_release=el7
fi
#本機ip
if [[ "$os_release" == "el6" ]];then
CHECK_IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'|head -1`
elif [[ "$os_release" == "el7" ]];then
CHECK_IP=`ifconfig |grep netmask|grep -v 127.0.0.1 |awk '{ print $2 }'|head -1`
fi
log=/home/sa/${CHECK_IP}_Disk.log
Disk=`cat /proc/partitions |awk '{print $4}'|grep -v '[0-9]'|grep -v name|grep -Ev "^$|[#;]"`
echo "磁碟檢查開始" >$log
#計數
NUMBER_COUNT_1=0
for i in $Disk
do
#判讀是否有分盤
NumberDisk=`lsblk |grep $i|wc -l`
if [ $NumberDisk = 1 ]
then
#判斷是否直接掛載
Mount=`lsblk|grep -w $i|awk '{print $7}'`
if [ "$Mount" = "" ]
then
#判斷是否劃分VG
VgDecide=`pvdisplay|grep Name|grep -w $i`
if [ "$VgDecide" = "" ]
then
#未使用磁碟空間
DiskSpace=`lsblk|grep -w $i|awk '{print $4}'`
echo "檢查IP:${CHECK_IP} 存在未掛載磁碟:${i} 磁碟空間為:${DiskSpace}" >>$log
NUMBER_COUNT_1=$((${NUMBER_COUNT_1}+1))
fi
fi
fi

done
if [[ ${NUMBER_COUNT_1} = 0 ]];
then
echo "${CHECK_IP}磁碟已全部掛載" >>$log
fi
cat $log