#!/bin/shSCRIPT_NAME=`basename $0`HOST_NAME=`hostname`DATE_FLAG=`date +%Y%m%d%H`GET_DATE_FLAG=`date +%Y%m%d`TMP_DIR="/tmp/mul_dir_ald"CONFIG_DIR="/etc/paic/check_disk"DISK_EXCLUDE="${CONFIG_DIR}/disk.exclude"DISK_PATH_ERROR="/tmp/check_lun_path.log"TMP_LOG_ALL_LUN="${TMP_DIR}/all_disks_info_output"TMP_LOG_ALL="${TMP_DIR}/all_disks_output"MULTIPATH_CMD="/sbin/multipath"PVSCAN_CMD="/sbin/pvscan"CSPLIT_CMD="/usr/bin/csplit"HBA_DIR="/sys/class/fc_host"CHECK_RESULT="${TMP_DIR}/${HOST_NAME}_${DATE_FLAG}_check"GET_RESULT="/tmp/hostluninfoget_diskinfofile_${HOST_NAME}_${GET_DATE_FLAG}"MULTIPATH_V3_RESULT="${TMP_DIR}/multipath_v3_output"PVSCAN_OUTPUT="${TMP_DIR}/pvscan_output"PVSCAN_FLAG=0DEV_MAPPER_DIR="/dev/mapper"ASM_DISK_DIR="/dev/oracleasm/disks"ASM_OUTPUT="${TMP_DIR}/asm_output_file.log"RELEASE_FILE="/etc/redhat-release"## For vxvm#VXDG_CMD="/sbin/vxdg"VXDISK_CMD="/sbin/vxdisk"VXDMPINQ_CMD="/etc/vx/diag.d/vxdmpinq"VXPRINT_CMD="/sbin/vxprint"DEVICE_DIR="/sys/block"VXDISK_OUTPUT="${TMP_DIR}/vxdisk_output_ald"HBA_NUM_OUTPUT="${TMP_DIR}/hba_bus_number"## For df result#DF_RESULT_FILE="/tmp/hostluninfoget_dfinfo_${HOST_NAME}_${GET_DATE_FLAG}"ASM_DF_OUTPUT="/tmp/asm_df_output_${HOST_NAME}_${GET_DATE_FLAG}"DF_DEV_OUTPUT="/tmp/df_dev_output_${HOST_NAME}_${GET_DATE_FLAG}"VGDISPLAY_CMD="/usr/sbin/vgdisplay"if [ ! -f ${VGDISPLAY_CMD} ]; then VGDISPLAY_CMD="/sbin/vgdisplay"fiBC_CMD="/usr/bin/bc"ID_CMD="/usr/bin/id"GRID_FLAG=0VGDISPLAY_OUTPUT="/tmp/vgdisplay_output_${HOST_NAME}_${GET_DATE_FLAG}"CHECK_FLAG=0GET_FLAG=0GET_DF_FLAG=0##create_dir (){ if [ -d ${TMP_DIR} ]; then : else mkdir ${TMP_DIR} chmod 777 ${TMP_DIR} fi if [ -d ${CONFIG_DIR} ]; then : else mkdir -p ${CONFIG_DIR} chmod 755 ${CONFIG_DIR} fi if [ -f ${DISK_EXCLUDE} ]; then : else echo "##########################################################################" > ${DISK_EXCLUDE} echo "# Pls put the disks that need not check the paths into this file and the #">> ${DISK_EXCLUDE} echo "# format of disk name should be start with it and end with it[should not #">> ${DISK_EXCLUDE} echo "# include any space of \" \" in the end]. #">> ${DISK_EXCLUDE} echo "##########################################################################" >> ${DISK_EXCLUDE} chmod 755 ${DISK_EXCLUDE} fi if [ -f ${DISK_PATH_ERROR} ]; then : else touch ${DISK_PATH_ERROR} fi}##check_paths_multipath (){ # # create_dir # # Get the disk name # if [ ! -x ${MULTIPATH_CMD} ]; then echo "The command of is not exist." return fi ${MULTIPATH_CMD} -ll > ${TMP_LOG_ALL_LUN} if [ $? -ne 0 ]; then echo "Running failed." return fi if [ ! -s ${TMP_LOG_ALL_LUN} ]; then echo "The output file of is not exist or empty." return fi cat ${TMP_LOG_ALL_LUN} | grep '(' > ${TMP_LOG_ALL} if [ ! -s ${TMP_LOG_ALL} ]; then echo "The output file of is not exist or empty." return fi ${MULTIPATH_CMD} -v3 > ${MULTIPATH_V3_RESULT} if [ ! -s ${MULTIPATH_V3_RESULT} ]; then echo "The output file of is not exist or empty." return fi # # Split the multipath output into single file for each LUN # ( COUNT_LINE=`cat ${TMP_LOG_ALL} | wc -l` NUM_CHAR=`echo ${COUNT_LINE} | wc -c` cd ${TMP_DIR} ${CSPLIT_CMD} -f lun -ks -n ${NUM_CHAR} ${TMP_LOG_ALL_LUN} '/(/' {${COUNT_LINE}} > /dev/null 2>&1 ) while read LINE; do LUN_NAME=`echo ${LINE} | awk '{print $1}'` LUN_WWIDS=`echo ${LINE} | awk '{print $2}'` VENDOR=`echo ${LINE} | awk '{print $4}' | awk -F',' '{print $1}'` STOR_TYPE=`echo ${LINE} | awk '{print $4}' | awk -F',' '{print $2}'` LUN_WWID= # # Delete the prefix of 3 for EMC and HP mid-storage # if [ "${VENDOR}" = "DGC" ]; then VENDOR="EMC" LUN_WWID=`echo ${LUN_WWIDS} | sed 's/^3//'` elif [ "${VENDOR}" = "HP" ]; then if `echo ${STOR_TYPE} | grep -i HSV > /dev/null`; then LUN_WWID=`echo ${LUN_WWIDS} | sed 's/^3//'` fi elif [ "${VENDOR}" = "EMC" -a "${STOR_TYPE}" = "SYMMETRIX" ]; then LUN_WWID=`echo ${LUN_WWIDS} | sed 's/^3//'` fi # # Get lun id[The last four characters] as UUID for advance storage # if `echo "${STOR_TYPE}" | grep "OPEN-V" > /dev/null`; then LUN_WWID=`expr "${LUN_WWIDS}" : '.*\(....\)'` fi if `cat ${DISK_EXCLUDE} | grep "^${LUN_NAME}$" > /dev/null`; then continue else TMP_LOG_SING=`grep "^${LUN_NAME} " ${TMP_DIR}/lun* |awk -F':' '{print $1}'` # # To check if there is any useless info from multipath command output # LINE_NUMB=`grep -n ${LUN_NAME} ${TMP_LOG_SING} | awk -F':' '{print $1}'` if [ ${LINE_NUMB} -ne 1 ]; then ALL_LINE_NUMB=`cat ${TMP_LOG_SING} | wc -l ` BOTTOM_LINE=`expr ${ALL_LINE_NUMB} - ${LINE_NUMB}` tail -${BOTTOM_LINE} ${TMP_LOG_SING} > ${TMP_LOG_SING}_tmp mv ${TMP_LOG_SING}_tmp ${TMP_LOG_SING} fi # # To get the size of the lun # LUN_SIZE=`grep size= ${TMP_LOG_SING} | awk '{print $1}' | awk -F'=' '{print $2}' | awk -F']' '{print $1}'` # # To get the storage serial # DEVICE_NAME=`grep ':' ${TMP_LOG_SING} | awk '{print $3}' | grep -v ':' |head -1` # # The tgt_node_name is the EVA serial from multipath -v3 output # if `echo ${STOR_TYPE} | grep -i HSV > /dev/null`; then STORAGE_SERIAL=`grep "${DEVICE_NAME}: " ${MULTIPATH_V3_RESULT} |grep "tgt_node_name =" | awk -F'=' '{print $2}' | sed -e 's/ //g' -e 's/^0x//'` else STORAGE_SERIAL=`grep "${DEVICE_NAME}: " ${MULTIPATH_V3_RESULT} |grep "serial = " | awk -F'=' '{print $2}' | sed 's/ //g'` fi # # For NETAPP storage,the serial from multipath -v3 output is the disk serial # if [ "${VENDOR}" = "NETAPP" ]; then LUN_WWID="${STORAGE_SERIAL}" STORAGE_SERIAL= fi # # Remove useless info. from the serial string # if [ "${VENDOR}" = "EMC" -a "${STOR_TYPE}" = "SYMMETRIX" ]; then STORAGE_SERIALS="${STORAGE_SERIAL}" STORAGE_SERIAL=`expr "${STORAGE_SERIALS}" : '\(......\).*'` fi # # The storage serial include LUN ID for HITACHI AMS # if [ "${VENDOR}" = "HITACHI" -a "${STOR_TYPE}" = "DF600F" ]; then STORAGE_SERIALS="${STORAGE_SERIAL}" STORAGE_SERIAL=`expr "${STORAGE_SERIALS}" : '\(........\).*'` LUN_WWID=`expr "${STORAGE_SERIALS}" : '.*\(....\)'` fi # # For IBM SVC,the serial from multipath -v3 output should remove the XX.* # if [ "${VENDOR}" = "IBM" ]; then STORAGE_SERIAL=`echo ${STORAGE_SERIAL} | sed 's/XX.*//g'` LUN_WWID=`echo ${LUN_WWIDS} | sed 's/^3//'` fi # # The multipath -v3 output may not start with devcie name # if [ "${STORAGE_SERIAL}x" = "x" -a "${LUN_WWID}x" = "x" ]; then get_stor_serial_lun_id ${LUN_WWIDS} ${DEVICE_NAME} STORAGE_SERIAL=`cat ${TMP_DIR}/storage_serial.txt` LUN_WWID=`cat ${TMP_DIR}/lun_wwid.txt` fi # # To check if the active paths are odd # ACTIVE_PATH_NUM=`grep active ${TMP_LOG_SING} | egrep -vi "prio=|round-robin" | wc -l` if `echo "1357911" | grep "${ACTIVE_PATH_NUM}" > /dev/null`; then #echo "[${HOST_NAME}] ${LUN_NAME}[${LUN_SIZE};${STORAGE_SERIAL}] active path number is ${ACTIVE_PATH_NUM}!" >> ${CHECK_RESULT} echo "[ALERT]: [${HOST_NAME}] ${LUN_NAME}[${LUN_SIZE};${STORAGE_SERIAL}] active path number is ${ACTIVE_PATH_NUM}!" >> ${DISK_PATH_ERROR} fi # # To check the failed path # #HBA_HOST_NUMS=`egrep "failed|faulty" ${TMP_LOG_SING} | egrep -vi "prio=|round-robin" | awk '{print $2}' | awk -F':' '{print $1}' | sed -e 's/-//g' -e 's/`//g' -e s'/|//g'` HBA_HOST_NUMS=`egrep "failed|faulty" ${TMP_LOG_SING} | egrep -vi "prio=|round-robin" | awk -F':' '{print $1}' | sed -e 's/-//g' -e 's/\`//g' -e 's/|//g' -e 's/\\\//g' -e 's/_//g' -e 's/ //g'` if [ "${HBA_HOST_NUMS}x" != "x" ]; then for HBA_HOST_NUM in ${HBA_HOST_NUMS}; do HBA_EXIST=`grep active ${TMP_LOG_SING} | egrep -vi "prio=|round-robin" | grep " ${HBA_HOST_NUM}:"` # # To check if the hba's failed path has any active path if [ "${HBA_EXIST}x" = "x" ]; then if [ -d ${HBA_DIR}/host${HBA_HOST_NUM} ]; then HBA_WWN=`cat ${HBA_DIR}/host${HBA_HOST_NUM}/port_name` HBA_SPEED=`cat ${HBA_DIR}/host${HBA_HOST_NUM}/speed |sed 's/ //g'` #echo "[${HOST_NAME}] ${LUN_NAME}[${LUN_SIZE};${STORAGE_SERIAL}] ALL paths down in hba${HBA_HOST_NUM}[${HBA_SPEED};${HBA_WWN}]!" >> ${CHECK_RESULT} echo "[ALERT]: [${HOST_NAME}] ${LUN_NAME}[${LUN_SIZE};${STORAGE_SERIAL}] ALL paths down in hba${HBA_HOST_NUM}[${HBA_SPEED};${HBA_WWN}]!" >> ${DISK_PATH_ERROR} else echo "The hba file does not exist,ignore the failed path." echo "[ALERT]: [${HOST_NAME}] ${LUN_NAME}[${LUN_SIZE};${STORAGE_SERIAL}] ALL paths down in hba${HBA_HOST_NUM}[${HBA_SPEED};${HBA_WWN}]!" >> ${DISK_PATH_ERROR} fi else HBA_WWN=`cat ${HBA_DIR}/host${HBA_HOST_NUM}/port_name` HBA_SPEED=`cat ${HBA_DIR}/host${HBA_HOST_NUM}/speed |sed 's/ //g'` #echo "[${HOST_NAME}] ${LUN_NAME}[${LUN_SIZE};${STORAGE_SERIAL}] some paths down in hba${HBA_HOST_NUM}[${HBA_SPEED};${HBA_WWN}]!" >> ${CHECK_RESULT} echo "[ALERT]: [${HOST_NAME}] ${LUN_NAME}[${LUN_SIZE};${STORAGE_SERIAL}] some paths down in hba${HBA_HOST_NUM}[${HBA_SPEED};${HBA_WWN}]!" >> ${DISK_PATH_ERROR} fi done fi # # To check if the active paths are all in the same fabric or not # FABRIC_NUM=`grep active ${TMP_LOG_SING} | egrep -vi "prio=|round-robin" | sed 's/^|//g' | awk '{print $2}' |awk -F':' '{print $1}' |sort -u | wc -l` if [ ${FABRIC_NUM} -le 1 ]; then #echo "[${HOST_NAME}] ${LUN_NAME}[${LUN_SIZE};${STORAGE_SERIAL}] all paths in single fabric!" >> ${CHECK_RESULT} echo "[ALERT]: [${HOST_NAME}] ${LUN_NAME}[${LUN_SIZE};${STORAGE_SERIAL}] all paths in single fabric!" >> ${DISK_PATH_ERROR} else # # Check for RedHat5,as RedHat4 has not the recode of switch wwn # RELEASE_FLAG=`cat ${RELEASE_FILE} | grep -i "release 5"` if [ "${RELEASE_FLAG}x" != "x" ]; then FABRIC_NUMS=`grep active ${TMP_LOG_SING} | egrep -vi "prio=|round-robin" | sed 's/^|//g' | awk '{print $2}' |awk -F':' '{print $1}' |sort -u` rm /tmp/switch_wwn_tmpfile for FABRIC_NUM in ${FABRIC_NUMS}; do cat ${HBA_DIR}/host${FABRIC_NUM}/fabric_name >> /tmp/switch_wwn_tmpfile done SW_WWN_NUMS=`cat /tmp/switch_wwn_tmpfile | sort -u | wc -l` if [ ${SW_WWN_NUMS} -le 1 ]; then #echo "[${HOST_NAME}] ${LUN_NAME}[${LUN_SIZE};${STORAGE_SERIAL}] all paths in single fabric!" >> ${CHECK_RESULT} echo "[ALERT]: [${HOST_NAME}] ${LUN_NAME}[${LUN_SIZE};${STORAGE_SERIAL}] all paths in single fabric!" >> ${DISK_PATH_ERROR} fi fi fi fi done}##check_paths_vxvm (){ DAEMON_RUN=`ps -ef | grep vxconfigd | grep -v grep` if [ "${DAEMON_RUN}x" = "x" ]; then echo "The daemon of is not running." return fi ALL_DG=`${VXDG_CMD} list | grep -v "^NAME" | awk '{print $1}'` if [ "${ALL_DG}x" = "x" ]; then echo "No dg exist in the host." return fi for SING_DG in ${ALL_DG}; do ALL_LUN=`${VXPRINT_CMD} -dg ${SING_DG} | grep "^dm" | awk '{print $3}'` for SING_LUN in ${ALL_LUN}; do if `cat ${DISK_EXCLUDE} | grep "^${SING_LUN}$" > /dev/null`; then continue else ${VXDISK_CMD} list ${SING_LUN} > ${VXDISK_OUTPUT} if [ $? -ne 0 ]; then echo "Running failed." continue fi # Check if path number is odd ENABLE_PATH_NUM=`cat ${VXDISK_OUTPUT} | grep 'state=enabled' | wc -l` if `echo "1357911" | grep "${ENABLE_PATH_NUM}" > /dev/null`; then echo "[ALERT]: [${HOST_NAME}] ${SING_LUN}[${SING_DG}] active path number is ${ACTIVE_PATH_NUM}!" >> ${DISK_PATH_ERROR} fi # Check if any disable path DISABLED_PATH=`cat ${VXDISK_OUTPUT} | grep 'state=disabled'` if [ "${DISABLED_PATH}x" != "x" ]; then echo "[ALERT]: [${HOST_NAME}] ${SING_LUN}[${SING_DG}] has disabled path of `cat ${VXDISK_OUTPUT} | grep 'state=disabled'`!" >> ${DISK_PATH_ERROR} fi # Check if the enable path in the same fabric DEVICES_NAME=`cat ${VXDISK_OUTPUT} | grep 'state=enabled' | awk '{print $1}'` cat /dev/null > ${HBA_NUM_OUTPUT} for DEVICE_NAME in ${DEVICES_NAME}; do ls -l ${DEVICE_DIR}/${DEVICE_NAME} | grep device | awk '{print $NF}' | awk -F'/' '{print $NF}' | awk -F':' '{print $1}' >> ${HBA_NUM_OUTPUT} done HBA_BUS_NUM=`cat ${HBA_NUM_OUTPUT} | sort -u | wc -l` if [ ${HBA_BUS_NUM} -le 1 ]; then echo "[ALERT]: [${HOST_NAME}] ${SING_LUN}[${SING_DG}] all paths in single fabric!" >> ${DISK_PATH_ERROR} fi fi done done}## $1 = lun wwid# $2 = device name#get_stor_serial_lun_id (){ LUN_WWIDS=$1 DEVICE_NAME=$2 # # split the multipath -v3 output based on each device # ( cd ${TMP_DIR} HEADER_FILE=`grep -n "===== path info" ${MULTIPATH_V3_RESULT} | head -1 | awk -F':' '{print $1}'` TOTAL_LINE=`cat ${MULTIPATH_V3_RESULT} | wc -l` CONTENT_LINES=`expr ${TOTAL_LINE} - ${HEADER_FILE}` CONTENT_LINE=`expr ${CONTENT_LINES} + 1` tail -${CONTENT_LINE} ${MULTIPATH_V3_RESULT} > ${MULTIPATH_V3_RESULT}_tmp001 TAIL_FILE=`grep -n "all paths" ${MULTIPATH_V3_RESULT}_tmp001 | head -1 | awk -F':' '{print $1}'` head -${TAIL_FILE} ${MULTIPATH_V3_RESULT}_tmp001 > ${MULTIPATH_V3_RESULT} rm ${MULTIPATH_V3_RESULT}_tmp001 FILES_NUMS=`grep -c "===== path info" ${MULTIPATH_V3_RESULT}` FILES_NUM=`expr ${FILES_NUMS} - 1` SUFFIX_NUM=`echo ${FILES_NUM} | wc -c` ${CSPLIT_CMD} -f multipathv3 -ks -n ${SUFFIX_NUM} ${MULTIPATH_V3_RESULT} '/===== path info /' {${FILES_NUM}} DEVICE_FILE_NAME=`grep ${DEVICE_NAME} multipathv3* | awk -F':' '{print $1}'` STORAGE_SERIAL=`grep serial ${DEVICE_FILE_NAME} | awk '{print $3}'` VENDOR=`grep vendor ${DEVICE_FILE_NAME} | awk '{print $3}'` STOR_TYPE=`grep product ${DEVICE_FILE_NAME} | awk '{print $3}'` # # Delete the prefix of 3 for EMC and HP mid-storage # if [ "${VENDOR}" = "DGC" ]; then VENDOR="EMC" LUN_WWID=`echo ${LUN_WWIDS} | sed 's/^3//'` elif [ "${VENDOR}" = "HP" ]; then if `echo ${STOR_TYPE} | grep -i HSV > /dev/null`; then LUN_WWID=`echo ${LUN_WWIDS} | sed 's/^3//'` STORAGE_SERIAL=`grep tgt_node_name ${DEVICE_FILE_NAME} | awk '{print $3}' | sed 's/^0x//'` fi elif [ "${VENDOR}" = "EMC" -a "${STOR_TYPE}" = "SYMMETRIX" ]; then LUN_WWID=`echo ${LUN_WWIDS} | sed 's/^3//'` fi # # Get lun id[The last four characters] as UUID for advance storage # if `echo "${STOR_TYPE}" | grep "OPEN-V" > /dev/null`; then LUN_WWID=`expr "${LUN_WWIDS}" : '.*\(....\)'` fi echo "${STORAGE_SERIAL}" > storage_serial.txt echo "${LUN_WWID}" > lun_wwid.txt )}##get_config_multipath (){ rm -f /tmp/hostluninfoget_diskinfofile* #cat /dev/null > ${GET_RESULT} #find /tmp/ -name "hostluninfoget_diskinfofile_*" -mtime +7 -exec rm -f {} \; # # create_dir # # Get the disk name # if [ ! -x ${MULTIPATH_CMD} ]; then echo "The command of is not exist." return fi ${MULTIPATH_CMD} -ll > ${TMP_LOG_ALL_LUN} if [ $? -ne 0 ]; then echo "Running failed." return fi if [ ! -s ${TMP_LOG_ALL_LUN} ]; then echo "The output file of is not exist or empty." return fi cat ${TMP_LOG_ALL_LUN} | grep '(' > ${TMP_LOG_ALL} if [ ! -s ${TMP_LOG_ALL} ]; then echo "The output file of is not exist or empty." return fi ${MULTIPATH_CMD} -v3 > ${MULTIPATH_V3_RESULT} if [ ! -s ${MULTIPATH_V3_RESULT} ]; then echo "The output file of is not exist or empty." return fi ${PVSCAN_CMD} > ${PVSCAN_OUTPUT} 2>/dev/null if [ $? -ne 0 ]; then echo "Running failed." PVSCAN_FLAG=1 fi # # Get the ASM config # ASM_SID=`ps -ef | grep pmon | grep ASM | awk '{print $NF}' | awk -F'_' '{print $3}' | head -1` if [ "${ASM_SID}x" != "x" ]; then # # The grid account does not exists in 10g asm # ${ID_CMD} grid > /dev/null 2>&1 if [ $? -eq 0 ]; thenQUERY_STRING="ORACLE_SID=${ASM_SID}export ORACLE_SIDsqlplus '/as sysdba'select a.label||'#'||b.name as name from v\\\$asm_disk a, v\\\$asm_diskgroup b where a.GROUP_NUMBER=b.GROUP_NUMBER;EOF" su - grid -c "${QUERY_STRING}" > ${ASM_OUTPUT}QUERY_STRING2="sqlplus '/as sysdba'set line 120column NAME format a40column PATH format a40spool /tmp/mul_dir_ald/asm_output_file2.logselect a.path||'#'||b.name as name from v\\\$asm_disk a, v\\\$asm_diskgroup b where a.GROUP_NUMBER=b.GROUP_NUMBER;spool offEOF" su - grid -c "${QUERY_STRING2}" > /dev/null 2>&1 else # # Tag GRID_FLAG to specify the grid account does not exist and will be used # in the following part. # GRID_FLAG=1 ASM_ACCOUNT=`ps -ef | grep pmon | grep ASM | awk '{print $1}' | head -1`QUERY_STRING="sqlplus '/as sysdba'set line 120column NAME format a40column PATH format a40spool /tmp/mul_dir_ald/asm_output_file.logselect a.path||'#'||b.name as name from v\\\$asm_disk a, v\\\$asm_diskgroup b where a.GROUP_NUMBER=b.GROUP_NUMBER;spool offEOF" su - ${ASM_ACCOUNT} -c "${QUERY_STRING}" > /dev/null 2>&1 fi fi # # Split the multipath output into single file for each LUN # ( COUNT_LINE=`cat ${TMP_LOG_ALL} | wc -l` NUM_CHAR=`echo ${COUNT_LINE} | wc -c` cd ${TMP_DIR} ${CSPLIT_CMD} -f lun -ks -n ${NUM_CHAR} ${TMP_LOG_ALL_LUN} '/(/' {${COUNT_LINE}} > /dev/null 2>&1 ) while read LINE; do LUN_NAME=`echo ${LINE} | awk '{print $1}'` LUN_WWIDS=`echo ${LINE} | awk '{print $2}' |sed -e 's/(//g' -e 's/)//g'` DM_NAME=`echo ${LINE} | awk '{print $3}'` VENDOR=`echo ${LINE} | awk '{print $4}' | awk -F',' '{print $1}'` #STOR_TYPE=`echo ${LINE} | awk '{print $4}' | awk -F',' '{print $2}'` STOR_TYPE=`echo ${LINE} | awk '{print $4 $5}' | awk -F',' '{print $2}'` LUN_WWID= # # Delete the prefix of 3 for EMC and HP mid-storage # if [ "${VENDOR}" = "DGC" ]; then VENDOR="EMC" LUN_WWID=`echo ${LUN_WWIDS} | sed 's/^3//'` elif [ "${VENDOR}" = "HP" ]; then if `echo ${STOR_TYPE} | grep -i HSV > /dev/null`; then LUN_WWID=`echo ${LUN_WWIDS} | sed 's/^3//'` fi elif [ "${VENDOR}" = "EMC" -a "${STOR_TYPE}" = "SYMMETRIX" ]; then LUN_WWID=`echo ${LUN_WWIDS} | sed 's/^3//'` fi # # Get lun id[The last four characters] as UUID for advance storage # if `echo "${STOR_TYPE}" | grep "OPEN-V" > /dev/null`; then LUN_WWID=`expr "${LUN_WWIDS}" : '.*\(....\)'` fi TMP_LOG_SING=`grep "^${LUN_NAME} " ${TMP_DIR}/lun* |awk -F':' '{print $1}'` # # To check if there is any useless info from multipath command output # LINE_NUMB=`grep -n ${LUN_NAME} ${TMP_LOG_SING} | awk -F':' '{print $1}'` if [ ${LINE_NUMB} -ne 1 ]; then ALL_LINE_NUMB=`cat ${TMP_LOG_SING} | wc -l ` BOTTOM_LINE=`expr ${ALL_LINE_NUMB} - ${LINE_NUMB}` tail -${BOTTOM_LINE} ${TMP_LOG_SING} > ${TMP_LOG_SING}_tmp mv ${TMP_LOG_SING}_tmp ${TMP_LOG_SING} fi # # To get the DG name of LVM # if [ "${PVSCAN_FLAG}" = "1" ]; then DG_NAME= elif [ ! -s ${PVSCAN_OUTPUT} ]; then DG_NAME= else DG_EXPORT_FLAG=`grep -i "/${LUN_NAME} " ${PVSCAN_OUTPUT} | grep "is in exported"` if [ "${DG_EXPORT_FLAG}x" = "x" ]; then DG_NAME=`grep -i "/${LUN_NAME} " ${PVSCAN_OUTPUT} | awk '{print $4}'` else DG_NAME=`grep -i "/${LUN_NAME} " ${PVSCAN_OUTPUT} | awk '{print $7}'` fi if [ "${DG_NAME}x" = "x" ]; then DG_EXPORT_FLAG=`grep -i "/${LUN_NAME}p1 " ${PVSCAN_OUTPUT} | grep "is in exported"` if [ "${DG_EXPORT_FLAG}x" = "x" ]; then DG_NAME=`grep -i "/${LUN_NAME}p1 " ${PVSCAN_OUTPUT} | awk '{print $4}'` else DG_NAME=`grep -i "/${LUN_NAME}p1 " ${PVSCAN_OUTPUT} | awk '{print $7}'` fi fi if [ "${DG_NAME}x" = "x" ]; then DG_EXPORT_FLAG=`grep -i "/${DM_NAME} " ${PVSCAN_OUTPUT} | grep "is in exported"` if [ "${DG_EXPORT_FLAG}x" = "x" ]; then DG_NAME=`grep -i "/${DM_NAME} " ${PVSCAN_OUTPUT} | awk '{print $4}'` else DG_NAME=`grep -i "/${DM_NAME} " ${PVSCAN_OUTPUT} | awk '{print $7}'` fi fi fi # # To get the DG name of ASM # if [ "${DG_NAME}x" = "x" ]; then if `grep NAME ${ASM_OUTPUT} > /dev/null`; then # # If it is the 10g asm, the disk will not be tag by kpartx # if [ "${GRID_FLAG}" = "1" ]; then DEV_FLAG=`ls -l ${DEV_MAPPER_DIR} | grep " ${LUN_NAME}" | cut -c 1` if [ "${DEV_FLAG}" = "l" ]; then REAL_DEV=`ls -l ${DEV_MAPPER_DIR} | grep " ${LUN_NAME}" | awk '{print $NF}'` cd ${DEV_MAPPER_DIR};MINOR_NUM=`ls -l ${REAL_DEV} | awk '{print $5" "$6}'` else MINOR_NUM=`ls -l ${DEV_MAPPER_DIR} | grep " ${LUN_NAME}" | awk '{print $5" "$6}'` fi else DEV_FLAG=`ls -l ${DEV_MAPPER_DIR} | grep " ${LUN_NAME}p1" | cut -c 1` if [ "${DEV_FLAG}" = "l" ]; then REAL_DEV=`ls -l ${DEV_MAPPER_DIR} | grep " ${LUN_NAME}p1" | awk '{print $NF}'` cd ${DEV_MAPPER_DIR};MINOR_NUM=`ls -l ${REAL_DEV} | awk '{print $5" "$6}'` else MINOR_NUM=`ls -l ${DEV_MAPPER_DIR} | grep " ${LUN_NAME}p1" | awk '{print $5" "$6}'` fi fi if [ "${MINOR_NUM}x" = "x" ]; then DG_NAME="NULL" else ORACLE_ASM_DISK=`ls -l ${ASM_DISK_DIR} | grep " ${MINOR_NUM} " |awk '{print $NF}'` if [ "${ORACLE_ASM_DISK}x" = "x" ]; then MINOR_NUM_NEW=`echo ${MINOR_NUM} | sed 's/, /,[ ]*/g'` ORACLE_ASM_DISK=`ls -l ${ASM_DISK_DIR} | grep " ${MINOR_NUM_NEW} " |awk '{print $NF}'` fi #comment it as the [ ]* has include it #if [ "${ORACLE_ASM_DISK}x" = "x" ]; then # MINOR_NUM_NEW=`echo ${MINOR_NUM} | sed 's/, /, /g'` # ORACLE_ASM_DISK=`ls -l ${ASM_DISK_DIR} | grep " ${MINOR_NUM_NEW} " |awk '{print $NF}'` #fi if [ "${ORACLE_ASM_DISK}x" = "x" ]; then DG_NAME="NULL" else # # If it is the 10g asm, the disk will not be tag by kpartx # if [ "${GRID_FLAG}" = "1" ]; then DG_NAME=`grep "${ORACLE_ASM_DISK}#" ${ASM_OUTPUT} | awk -F'#' '{print $2}'` else DG_NAME=`grep "^${ORACLE_ASM_DISK}#" ${ASM_OUTPUT} | awk -F'#' '{print $2}'` fi if [ "${DG_NAME}x" = "x" ]; then DG_NAME=`grep "${ORACLE_ASM_DISK}" /tmp/mul_dir_ald/asm_output_file2.log | awk '{print $2}'` fi if [ "${DG_NAME}x" = "x" ]; then DG_NAME="NULL" fi fi if [ "${DG_NAME}" = "NULL" ]; then DG_NAME=`grep -i "${LUN_NAME}#" ${ASM_OUTPUT} | awk -F'#' '{print $2}'` fi # # If the DG_NAME is more than 2,should get it from the head of # asm disk but not from v$asm_disk and v$asm_group # DG_NUMS=`echo ${DG_NAME} | wc -w` if [ ${DG_NUMS} -ge 2 ]; then # get the ORACLE_HOME first if [ "${GRID_FLAG}" = "1" ]; then KFED_PRE=`su - ${ASM_ACCOUNT} -c 'echo $ORACLE_HOME'` else KFED_PRE=`su - grid -c 'echo $ORACLE_HOME'` fi KFED_CMD="${KFED_PRE}/bin/kfed" DG_NAME=`${KFED_CMD} read ORCL:${ORACLE_ASM_DISK} |\ grep grpname | awk '{print $2}' | sed -e 's/;//g' -e 's/://g'` fi fi fi fi # # To get the size of the lun # LUN_SIZE=`grep size= ${TMP_LOG_SING} | awk '{print $1}' | awk -F'=' '{print $2}' | awk -F']' '{print $1}'` # # To get the storage serial # DEVICE_NAME=`grep ':' ${TMP_LOG_SING} | awk '{print $3}' |grep -v ':' | head -1` # # The tgt_node_name is the EVA serial from multipath -v3 output # if `echo ${STOR_TYPE} | grep -i HSV > /dev/null`; then STORAGE_SERIAL=`grep "${DEVICE_NAME}: " ${MULTIPATH_V3_RESULT} |grep "tgt_node_name =" | awk -F'=' '{print $2}' | sed -e 's/ //g' -e 's/^0x//'` else STORAGE_SERIAL=`grep "${DEVICE_NAME}: " ${MULTIPATH_V3_RESULT} |grep "serial = " | awk -F'=' '{print $2}' | sed 's/ //g'` fi # # For NETAPP storage,the serial from multipath -v3 output is the disk serial # if [ "${VENDOR}" = "NETAPP" ]; then LUN_WWID="${STORAGE_SERIAL}" STORAGE_SERIAL= fi # # Remove useless info. from the serial string # if [ "${VENDOR}" = "EMC" -a "${STOR_TYPE}" = "SYMMETRIX" ]; then STORAGE_SERIALS="${STORAGE_SERIAL}" STORAGE_SERIAL=`expr "${STORAGE_SERIALS}" : '\(......\).*'` fi # # The storage serial include LUN ID for HITACHI AMS # if [ "${VENDOR}" = "HITACHI" -a "${STOR_TYPE}" = "DF600F" ]; then STORAGE_SERIALS="${STORAGE_SERIAL}" STORAGE_SERIAL=`expr "${STORAGE_SERIALS}" : '\(........\).*'` LUN_WWID=`expr "${STORAGE_SERIALS}" : '.*\(....\)'` fi # # For IBM SVC,the serial from multipath -v3 output should remove the XX.* # if [ "${VENDOR}" = "IBM" ]; then STORAGE_SERIAL=`echo ${STORAGE_SERIAL} | sed 's/XX.*//g'` LUN_WWID=`echo ${LUN_WWIDS} | sed 's/^3//'` fi # # The multipath -v3 output may not start with devcie name # if [ "${STORAGE_SERIAL}x" = "x" -a "${LUN_WWID}x" = "x" ]; then get_stor_serial_lun_id ${LUN_WWIDS} ${DEVICE_NAME} STORAGE_SERIAL=`cat ${TMP_DIR}/storage_serial.txt` LUN_WWID=`cat ${TMP_DIR}/lun_wwid.txt` fi # # To get total path number # TOTAL_PATH=`grep ':' ${TMP_LOG_SING} | wc -l` # # To get active path number # ACTIVE_PATH=`grep ':' ${TMP_LOG_SING} | grep active | wc -l` # # To get failed path number # FAILED_PATH=`grep ':' ${TMP_LOG_SING} | grep falied | wc -l` # # Specify the DG_NAME as - if it is not exist # if [ "${DG_NAME}x" = "x" ]; then DG_NAME='-' fi # # make STORAGE_SERIAL for G1000 # STORAGE_SERIAL_NUM=`echo ${STORAGE_SERIAL} | wc -c` if [ ${STORAGE_SERIAL_NUM} -eq 7 ]; then if `echo ${STORAGE_SERIAL} | grep "^5" > /dev/null`; then STORAGE_SERIAL_NEW=`echo ${STORAGE_SERIAL} | cut -c 1-5` STORAGE_SERIAL="${STORAGE_SERIAL_NEW}" fi fi # # To get device name HBA and WWN # WWN_AND_SPEED= SWITCH_WWNS= HBA_DEVICES=`grep ':' ${TMP_LOG_SING} | sed 's/^|//g' |awk '{print $2","$3}'` for HBA_DEVICE in ${HBA_DEVICES}; do HBA_HOST=`echo ${HBA_DEVICE} | awk -F',' '{print $1}'|awk -F':' '{print $1}'` LUN_DEVICE=`echo ${HBA_DEVICE} | awk -F',' '{print "/dev/"$2}'` if [ -d ${HBA_DIR}/host${HBA_HOST} ]; then HBA_WWN=`cat ${HBA_DIR}/host${HBA_HOST}/port_name | sed 's/^0x//g'` HBA_SPEED=`cat ${HBA_DIR}/host${HBA_HOST}/speed |sed 's/ //g'` SWITCH_WWN=`cat ${HBA_DIR}/host${HBA_HOST}/fabric_name | sed 's/^0x//g'` echo "${LUN_NAME},${HOST_NAME},${DG_NAME},${STORAGE_SERIAL},${LUN_WWID},${ACTIVE_PATH},${FAILED_PATH},${LUN_DEVICE},${HBA_WWN},${HBA_SPEED},${SWITCH_WWN}" >> ${GET_RESULT} else echo "HBA file of is not exits." echo "${LUN_NAME},${HOST_NAME},${DG_NAME},${STORAGE_SERIAL},${LUN_WWID},${ACTIVE_PATH},${FAILED_PATH},${LUN_DEVICE},${HBA_WWN},${HBA_SPEED},${SWITCH_WWN}" >> ${GET_RESULT} fi done #echo "${LUN_NAME},${HOST_NAME} ${LUN_SIZE} ${TOTAL_PATH} ${ACTIVE_PATH} ${FAILED_PATH} ${STORAGE_SERIAL} ${VENDOR} ${LUN_WWID} ${DEVICE_NAMES} ${WWN_AND_SPEED} ${SWITCH_WWNS}" done}###get_config_vxvm (){ DAEMON_RUN=`ps -ef | grep vxconfigd | grep -v grep` if [ "${DAEMON_RUN}x" = "x" ]; then echo "The daemon of is not running." return fi #need to find the disk first but not DG 20150804 #ALL_DG=`${VXDG_CMD} list | grep -v "^NAME" | awk '{print $1}'` #if [ "${ALL_DG}x" = "x" ]; then # echo "No dg exist in the host." # return #fi ALL_LUN_FILE="/tmp/all_lun_info.$$" ALL_LUN=`${VXDISK_CMD} -o alldgs list | egrep -v "^DEVICE|invalid" > ${ALL_LUN_FILE}` #for SING_DG in ${ALL_DG}; do ALL_LUNS=`cat ${ALL_LUN_FILE} | awk '{print $1}'` for SING_LUN in ${ALL_LUNS}; do SING_DG=`grep "${SING_LUN} " ${ALL_LUN_FILE} | awk '{print $4}' | sed -e 's/)//g' -e 's/(//g'` ${VXDISK_CMD} list ${SING_LUN} > ${VXDISK_OUTPUT} if [ $? -ne 0 ]; then echo "Running failed." continue fi STORAGE_SERIAL_HEX=`grep "udid: " ${VXDISK_OUTPUT} | awk -F'%' '{print $(NF-1)}' | sed 's/^5F//'` if `echo "${STORAGE_SERIAL_HEX}" | grep -i disk > /dev/null`; then STORAGE_SERIAL_HEX_01=`grep "udid: " ${VXDISK_OUTPUT} | awk -F'%' '{print $NF}' | sed 's/^5F//'` if [ "${HOST_NAME}" = "cnsz081044" ]; then STORAGE_SERIAL_HEX=`expr "${STORAGE_SERIAL_HEX_01}" : '.*\(.....\)........'` else STORAGE_SERIAL_HEX=`expr "${STORAGE_SERIAL_HEX_01}" : '.*\(....\)........'` fi STORAGE_SERIAL=`echo "obase=10;ibase=16;${STORAGE_SERIAL_HEX}" | bc` LUN_WWID_01=`grep "udid: " ${VXDISK_OUTPUT} | awk -F'%' '{print $NF}' | sed 's/^5F//'` LUN_WWID=`expr "${LUN_WWID_01}" : '.*\(....\)'` #for svc elif `echo "${STORAGE_SERIAL_HEX}" | grep XX > /dev/null`; then STORAGE_SERIAL=`echo ${STORAGE_SERIAL_HEX} | sed 's/XX.*//'` LUN_WWID=`grep "udid: " ${VXDISK_OUTPUT} | awk -F'%' '{print $NF}' | sed 's/^5F//'` #for HDS storage else STORAGE_SERIAL=`echo "obase=10;ibase=16;${STORAGE_SERIAL_HEX}" | bc` LUN_WWID=`grep "udid: " ${VXDISK_OUTPUT} | awk -F'%' '{print $NF}' | sed 's/^5F//'` fi ACTIVE_PATH=`grep 'state=enabled' ${VXDISK_OUTPUT} | wc -l` FAILED_PATH=`grep 'state=disabled' ${VXDISK_OUTPUT} | wc -l` LUN_DEVICES=`grep 'state=' ${VXDISK_OUTPUT} | awk '{print $1}'` for LUN_DEVICE in ${LUN_DEVICES}; do HBA_NUM=`ls -l ${DEVICE_DIR}/${LUN_DEVICE} | grep device | awk '{print $NF}' | awk -F'/' '{print $NF}' | awk -F':' '{print $1}'` if [ -d ${HBA_DIR}/host${HBA_NUM} ]; then HBA_WWN=`cat ${HBA_DIR}/host${HBA_NUM}/port_name | sed 's/^0x//g'` HBA_SPEED=`cat ${HBA_DIR}/host${HBA_NUM}/speed |sed 's/ //g'` SWITCH_WWN=`cat ${HBA_DIR}/host${HBA_NUM}/fabric_name | sed 's/^0x//g'` echo "${SING_LUN},${HOST_NAME},${SING_DG},${STORAGE_SERIAL},${LUN_WWID},${ACTIVE_PATH},${FAILED_PATH},${LUN_DEVICE},${HBA_WWN},${HBA_SPEED},${SWITCH_WWN}" >> ${GET_RESULT} else echo "HBA file of is not exits." echo "${SING_LUN},${HOST_NAME},${SING_DG},${STORAGE_SERIAL},${LUN_WWID},${ACTIVE_PATH},${FAILED_PATH},${LUN_DEVICE},${HBA_WWN},${HBA_SPEED},${SWITCH_WWN}" >> ${GET_RESULT} fi done done #done rm ${ALL_LUN_FILE}}## $1 = The size with KB unit.#convert_size_unit (){ SIZE_WITH_KB=$1 SIZE_RESULT=`echo "${SIZE_WITH_KB}/1024/1024" | ${BC_CMD}` echo "${SIZE_RESULT}"}###get_df_config (){ rm -f /tmp/hostluninfoget_dfinfo* #cat /dev/null > ${DF_RESULT_FILE} #find /tmp/ -name "hostluninfoget_dfinfo_*" -mtime +7 -exec rm -f {} \; # # Get the ASM config # ASM_SID=`ps -ef | grep pmon | grep ASM | awk '{print $NF}' | awk -F'_' '{print $3}' | head -1` if [ "${ASM_SID}x" != "x" ]; thenQUERY_STRING="ORACLE_SID=${ASM_SID}export ORACLE_SIDsqlplus '/as sysdba'set pagesize 10000set linesize 10000select name,TOTAL_MB/1024 T_GB,FREE_MB/1024 F_GB,(TOTAL_MB-FREE_MB)/TOTAL_MB a from v\\\$asm_diskgroup where TOTAL_MB != 0;EOF" # # The grid account does not exists in 10g asm # ${ID_CMD} grid > /dev/null 2>&1 if [ $? -eq 0 ]; then su - grid -c "${QUERY_STRING}" > ${ASM_DF_OUTPUT} elseQUERY_STRING="sqlplus '/as sysdba'set pagesize 10000set linesize 10000select name,TOTAL_MB/1024 T_GB,FREE_MB/1024 F_GB,(TOTAL_MB-FREE_MB)/TOTAL_MB a from v\\\$asm_diskgroup where TOTAL_MB != 0;EOF" ASM_ACCOUNT=`ps -ef | grep pmon | grep ASM | awk '{print $1}' | head -1` su - ${ASM_ACCOUNT} -c "${QUERY_STRING}" > ${ASM_DF_OUTPUT} fi DECH_NUM=`grep -n -- "-----" ${ASM_DF_OUTPUT} | awk -F':' '{print $1}'` TOTAL_DECH=`cat ${ASM_DF_OUTPUT} | wc -l` CONTENT_LINE=`expr ${TOTAL_DECH} - ${DECH_NUM}` tail -${CONTENT_LINE} ${ASM_DF_OUTPUT} | sed '/^$/d' > ${ASM_DF_OUTPUT}_tmp001 BOOT_LINE=`grep -n "SQL>" ${ASM_DF_OUTPUT}_tmp001 | awk -F':' '{print $1}'` NEED_LINT=`expr ${BOOT_LINE} - 1` head -${NEED_LINT} ${ASM_DF_OUTPUT}_tmp001 | grep -v "rows selected" > ${ASM_DF_OUTPUT} rm ${ASM_DF_OUTPUT}_tmp001 #grep "DG" ${ASM_DF_OUTPUT} | \ cat ${ASM_DF_OUTPUT} | \ while read LINE; do ASM_DG_NAME=`echo ${LINE} | awk '{print $1}'` ASM_DG_TOTAL_SIZE=`echo ${LINE} | awk '{print $2}' | awk -F'.' '{print $1}'` ASM_DG_FREE_SIZE=`echo ${LINE} | awk '{print $3}' | awk -F'.' '{print $1}'` ASM_DG_USED_RATE1=`echo ${LINE} | awk '{print $4}'` ASM_DG_USED_RATE2=`expr "${ASM_DG_USED_RATE1}" : '.\(..\).*'` ASM_DG_USED_RATE=`echo ${ASM_DG_USED_RATE2}"%" | sed 's/^0//g'` SACNNAME=`cat /etc/hosts| grep scan|awk '{print $NF}'` DGID=`echo "${ASM_DG_NAME}_$SACNNAME"` echo "${HOST_NAME},${ASM_DG_NAME},NULL,${ASM_DG_TOTAL_SIZE},${ASM_DG_FREE_SIZE},NULL,NULL,NULL,${ASM_DG_USED_RATE},NULL,,$DGID" >> ${DF_RESULT_FILE} done rm -f ${ASM_DF_OUTPUT} fi # # Get the FS config # ${MULTIPATH_CMD} -ll > /tmp/multipath_ll_output_$$ df -h | egrep -v 'VolGroup00|Filesystem|tmp|boot|root|home' | grep dev | awk '{print $1}' > ${DF_DEV_OUTPUT} if [ -s ${DF_DEV_OUTPUT} ]; then MULTIPATH_VGS=`grep mapper ${DF_DEV_OUTPUT}` if [ "${MULTIPATH_VGS}x" != "x" ]; then for MULTIPATH_VG in ${MULTIPATH_VGS}; do VG_NAME=`echo ${MULTIPATH_VG} | awk -F'/' '{print $4}' | awk -F'-' '{print $1}'` DGID=`vgdisplay $VG_NAME| grep "VG UUID"|awk '{print $3}'` VOLUME_NAME=`echo ${MULTIPATH_VG} | awk -F'/' '{print $4}' | awk -F'-' '{print $2}'` ${VGDISPLAY_CMD} ${VG_NAME} > ${VGDISPLAY_OUTPUT} VG_TOTAL_SIZE_UNIT=`cat ${VGDISPLAY_OUTPUT} |grep "VG Size" |awk '{print $4}'` if [ "${VG_TOTAL_SIZE_UNIT}" = "GB" -o "${VG_TOTAL_SIZE_UNIT}" = "GiB" ]; then VG_TOTAL_SIZE=`cat ${VGDISPLAY_OUTPUT} |grep "VG Size" |awk '{print $3}' | awk -F'.' '{print $1}'` elif [ "${VG_TOTAL_SIZE_UNIT}" = "MB" -o "${VG_TOTAL_SIZE_UNIT}" = "MiB" ]; then VG_TOTAL_SIZE_MB=`cat ${VGDISPLAY_OUTPUT} |grep "VG Size" |awk '{print $3}' | awk -F'.' '{print $1}'` VG_TOTAL_SIZE=`expr ${VG_TOTAL_SIZE_MB} / 1024` elif [ "${VG_TOTAL_SIZE_UNIT}" = "TB" -o "${VG_TOTAL_SIZE_UNIT}" = "TiB" ]; then VG_TOTAL_SIZE_TB=`cat ${VGDISPLAY_OUTPUT} |grep "VG Size" |awk '{print $3}' | awk -F'.' '{print $1}'` VG_TOTAL_SIZE=`expr ${VG_TOTAL_SIZE_TB} \* 1024` fi VG_FREE_SIZE_UNIT=`cat ${VGDISPLAY_OUTPUT} |grep "Free PE" |awk '{print $8}'` if [ "${VG_FREE_SIZE_UNIT}" = "GB" -o "${VG_FREE_SIZE_UNIT}" = "GiB" ]; then VG_FREE_SIZE=`cat ${VGDISPLAY_OUTPUT} |grep "Free PE" |awk '{print $7}' | awk -F'.' '{print $1}'` elif [ "${VG_FREE_SIZE_UNIT}" = "MB" -o "${VG_FREE_SIZE_UNIT}" = "MiB" ]; then VG_FREE_SIZE_MB=`cat ${VGDISPLAY_OUTPUT} |grep "Free PE" |awk '{print $7}' | awk -F'.' '{print $1}'` VG_FREE_SIZE=`expr ${VG_FREE_SIZE_MB} / 1024` elif [ "${VG_FREE_SIZE_UNIT}" = "TB" -o "${VG_FREE_SIZE_UNIT}" = "TiB" ]; then VG_FREE_SIZE_TB=`cat ${VGDISPLAY_OUTPUT} |grep "Free PE" |awk '{print $7}' | awk -F'.' '{print $1}'` VG_FREE_SIZE=`expr ${VG_FREE_SIZE_TB} \* 1024` else if [ "${VG_TOTAL_SIZE}x" != "x" ]; then VG_FREE_SIZE=0 fi fi DF_LINE=`df -k ${MULTIPATH_VG} | grep -v Filesystem | grep '%'` FS_TOTAL_SIZE=`echo ${DF_LINE} | awk '{print $1}'` if `echo ${FS_TOTAL_SIZE} | grep mapper > /dev/null`; then FS_TOTAL_SIZE_TMP=`echo ${DF_LINE} | awk '{print $2}'` FS_TOTAL_SIZE=`convert_size_unit ${FS_TOTAL_SIZE_TMP}` FS_USED_SIZE_TMP=`echo ${DF_LINE} | awk '{print $3}'` FS_USED_SIZE=`convert_size_unit ${FS_USED_SIZE_TMP}` FS_FREE_SIZE_TMP=`echo ${DF_LINE} | awk '{print $4}'` FS_FREE_SIZE=`convert_size_unit ${FS_FREE_SIZE_TMP}` FS_USED_RATE=`echo ${DF_LINE} | awk '{print $5}'` FS_MOUNTPOINT=`echo ${DF_LINE} | awk '{print $6}'` else FS_TOTAL_SIZE_TMP=`echo ${DF_LINE} | awk '{print $1}'` FS_TOTAL_SIZE=`convert_size_unit ${FS_TOTAL_SIZE_TMP}` FS_USED_SIZE_TMP=`echo ${DF_LINE} | awk '{print $2}'` FS_USED_SIZE=`convert_size_unit ${FS_USED_SIZE_TMP}` FS_FREE_SIZE_TMP=`echo ${DF_LINE} | awk '{print $3}'` FS_FREE_SIZE=`convert_size_unit ${FS_FREE_SIZE_TMP}` FS_USED_RATE=`echo ${DF_LINE} | awk '{print $4}'` FS_MOUNTPOINT=`echo ${DF_LINE} | awk '{print $5}'` fi if [ "${VOLUME_NAME}x" = "x" -a "${VG_TOTAL_SIZE}x" = "x" -a "${VG_FREE_SIZE}x" = "x" ]; then DISK_NAME=`echo "${VG_NAME}" | sed 's/p.$//'` VG_NAME="${DISK_NAME}" DGID=`vgdisplay $VG_NAME| grep "VG UUID"|awk '{print $3}'` VG_TOTAL_SIZE=`cat /tmp/multipath_ll_output_$$ | grep -A 1 ${VG_NAME} | tail -1 | awk -F']' '{print $1}' | awk -F'=' '{print $2}' | sed 's/G//'` VOLUME_NAME=disk fi echo "${HOST_NAME},${VG_NAME},${VOLUME_NAME},${VG_TOTAL_SIZE},${VG_FREE_SIZE},${FS_TOTAL_SIZE},${FS_USED_SIZE},${FS_FREE_SIZE},${FS_USED_RATE},${FS_MOUNTPOINT},,$DGID" >> ${DF_RESULT_FILE} VG_TOTAL_SIZE="" VG_FREE_SIZE="" done fi VXVM_DGS=`grep '/vx/' ${DF_DEV_OUTPUT}` if [ "${VXVM_DGS}x" != "x" ]; then for VXVM_DG in ${VXVM_DGS}; do VXVM_DG_NAME=`echo ${VXVM_DG} | awk -F'/' '{print $5}'` DGID=`vxdg list| grep ${VXVM_DG_NAME}|awk '{print $NF}'` VXVM_VOLUME_NAME=`echo ${VXVM_DG} | awk -F'/' '{print $6}'` DG_TOTAL_SIZE=`${VXPRINT_CMD} -dg ${VXVM_DG_NAME} | grep "^dm" | awk '{total+=$5}'END'{printf "%d\n", total/1024/1024/2}'` DG_FREE_SIZE=`${VXDG_CMD} -g ${VXVM_DG_NAME} free | grep -v "LENGTH" | awk '{free+=$5}'END'{printf "%d\n", free/1024/1024/2}'` DG_USED_SIZE=`echo ${DG_TOTAL_SIZE} - ${DG_FREE_SIZE} | ${BC_CMD} -l` VXVM_DF_LINE=`df -k ${VXVM_DG} | grep -v Filesystem | grep '%'` FS_TOTAL_SIZE=`echo ${VXVM_DF_LINE} | awk '{print $1}'` if `echo ${FS_TOTAL_SIZE} | grep '/vx' > /dev/null`; then FS_TOTAL_SIZE_TMP=`echo ${VXVM_DF_LINE} | awk '{print $2}'` FS_TOTAL_SIZE=`convert_size_unit ${FS_TOTAL_SIZE_TMP}` FS_USED_SIZE_TMP=`echo ${VXVM_DF_LINE} | awk '{print $3}'` FS_USED_SIZE=`convert_size_unit ${FS_USED_SIZE_TMP}` FS_FREE_SIZE_TMP=`echo ${VXVM_DF_LINE} | awk '{print $4}'` FS_FREE_SIZE=`convert_size_unit ${FS_FREE_SIZE_TMP}` FS_USED_RATE=`echo ${VXVM_DF_LINE} | awk '{print $5}'` FS_MOUNTPOINT=`echo ${VXVM_DF_LINE} | awk '{print $6}'` else FS_TOTAL_SIZE_TMP=`echo ${VXVM_DF_LINE} | awk '{print $1}'` FS_TOTAL_SIZE=`convert_size_unit ${FS_TOTAL_SIZE_TMP}` FS_USED_SIZE_TMP=`echo ${VXVM_DF_LINE} | awk '{print $2}'` FS_USED_SIZE=`convert_size_unit ${FS_USED_SIZE_TMP}` FS_FREE_SIZE_TMP=`echo ${VXVM_DF_LINE} | awk '{print $3}'` FS_FREE_SIZE=`convert_size_unit ${FS_FREE_SIZE_TMP}` FS_USED_RATE=`echo ${VXVM_DF_LINE} | awk '{print $4}'` FS_MOUNTPOINT=`echo ${VXVM_DF_LINE} | awk '{print $5}'` fi if [ "${VXVM_DG_NAME}x" = "x" ]; then VXVM_DG_NAME='-' fi echo "${HOST_NAME},${VXVM_DG_NAME},${VXVM_VOLUME_NAME},${DG_TOTAL_SIZE},${DG_FREE_SIZE},${FS_TOTAL_SIZE},${FS_USED_SIZE},${FS_FREE_SIZE},${FS_USED_RATE},${FS_MOUNTPOINT},,$DGID" >> ${DF_RESULT_FILE} done fi rm -f ${DF_DEV_OUTPUT} ${VGDISPLAY_OUTPUT} /tmp/multipath_ll_output_$$ fi}###show_usage (){ echo "" echo "Usage:" echo "`basename $0` -h -c -g -d" echo " -h = Show this usage." echo " -c = Check the disk path." echo " -g = Get disk path configurations." echo " -d = Get df result informations." echo ""}#if [ $# -lt 1 ]; then# show_usage# exit 0#fi#while getopts \?hcgd flag; do# case ${flag} in# \?|h) show_usage# exit 0 ;;# c) CHECK_FLAG=1 ;;# g) GET_FLAG=1 ;;# d) GET_DF_FLAG=1 ;;# esac#doneGET_DF_FLAG=1GET_FLAG=1if [ "${CHECK_FLAG}" = "0" -a "${GET_FLAG}" = "0" -a "${GET_DF_FLAG}" = "0" ]; then show_usage exit 0fiif [ `/usr/bin/whoami` != "root" ]; then echo "This script should be runed by root." exit 1fiif [ "${CHECK_FLAG}" = "1" ]; then SCRIPT_RUNNING_FLAG=`ps -ef | grep "${SCRIPT_NAME} -c" | grep -v grep | wc -l` # # Will fork a new progress,so should be great than 3. # if [ ${SCRIPT_RUNNING_FLAG} -ge 3 ]; then echo "The check path script still running, pls wait." exit 1 fi # # Clear the old error log # cat /dev/null > ${DISK_PATH_ERROR} check_paths_multipath check_paths_vxvm if [ -s ${DISK_PATH_ERROR} ]; then cat ${DISK_PATH_ERROR} else echo "[OK]: [${HOST_NAME}] All paths are right." >> ${DISK_PATH_ERROR} fifiif [ "${GET_FLAG}" = "1" ]; then SCRIPT_RUNNING_FLAG=`ps -ef | grep -v "${SCRIPT_NAME} -c" | grep "${SCRIPT_NAME}" | grep -v grep | wc -l` if [ ${SCRIPT_RUNNING_FLAG} -ge 3 ]; then echo "This script still running, pls wait." exit 1 fi get_config_multipath get_config_vxvm chmod 644 ${GET_RESULT}fiif [ "${GET_DF_FLAG}" = "1" ]; then SCRIPT_RUNNING_FLAG=`ps -ef | grep -v "${SCRIPT_NAME} -c" | grep "${SCRIPT_NAME}" | grep -v grep | wc -l` if [ ${SCRIPT_RUNNING_FLAG} -ge 3 ]; then echo "This script still running, pls wait." exit 1 fi get_df_config chmod 644 ${DF_RESULT_FILE}firm -rf ${TMP_DIR}#echo collect debug infocurrentTime=`date "+%Y-%m-%d %H:%M:%S"`echo $currentTime 'End Collect' >> /home/stadmin/testdate.log 02-02 17:53