Shell脚本案例(二).检查summer服务mount点状态是否OK


我们要检测与summer服务相关的的mount点是否正常,首先需要知道与summer服务相关的mount点都有哪些?在summer服务的配置文件xxxconf.xml中配置有mount点的配置信息。所以第一步,我们要从配置文件中找出<MountPointPath>标签中的内容,即mount路径,并将mount路径暂存到conf_mount.list文件中。
summer服务需要的mount点可能不止一个,所以conf_mount.list中可能存在多个mount路径,要检查每一个mount点是否正常,就要对其进行循环遍历。
不同的文件类型,挂载在不同的路径下,所以需要先判断文件类型。
mount命令可以查询出所有的mount点,通过mount |grep "$mount_info" |wc -l命令查看是否有指定路径的mount点的数量。
如果数量不为0,表示有指定的mount点,在此基础上测试这个mount是否正常,可以通过touch一个文件的方式,测试是否正常




file_type_check()
{
    if [ -f "/usr/bin/mkmfsadm" ];then
        tmp_file_type="mkm"
    elif [ -f "/opt/SmartData/bin/smio_info" ];then
        tmp_file_type="smartdata"
    else
        tmp_file_type="unknow_filetype"
    fi
}


monitor_mount_state()
{
    num=0    


    iteration_result1=""

    tmp_file_type=""   
    file_type_check


    cat $summerconf|grep "<MountPointPath>" |awk -F'<|>' '{print $3}' > conf_mount.list
    for line in $(cat conf_mount.list)  
    do
        if [ "$tmp_file_type" = "mkm" ];then
            mount_info="/opt/mkmfs_fuse/$line"
            tmp_mount_count=`mount |grep "$mount_info" |wc -l`
        else
            mount_info="/home/summer/data/$line"
            tmp_mount_count=`mount |grep "$mount_info " |wc -l`
        fi
           
        if [ $tmp_mount_count -ne 0 ];then
            file_date=`date +%Y%m%d%H%M%S`
            touch /home/summer/data/$line/mounttest_$file_date 2>/dev/null;real_rm /home/summer/data/$line/mounttest_$file_date 2>/dev/null
            if [ $? = 0 ];then
                continue
            else
                if [ "X$iteration_result1" == "X" ];then
                    iteration_result1=$line
                else
                    iteration_result1=$iteration_result1" "$line
                fi
                num=`expr $num + 1`
                g_err_flag=1
            fi
        else
            if [ "X$iteration_result1" == "X" ];then
                iteration_result1=$line
            else
                iteration_result1=$iteration_result1" "$line
            fi
            num=`expr $num + 1`
            g_err_flag=1
        fi
    done


    if [ $num -eq 0 ];then
    echo "check_mount_status is OK"
    else
       
        echo "check_mount_status is WARN"
    fi
    rm -rf conf_mount.list
    return 0 
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章