Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1061836
  • 博文数量: 239
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 3618
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-12 13:17
文章分类

全部博文(239)

文章存档

2021年(1)

2016年(1)

2015年(30)

2014年(91)

2013年(116)

分类: LINUX

2021-07-04 19:25:13

#!/bin/sh
###############################################################################################################
#Script name: checkLinux.sh
#Script description: Linux Check
#Current Release Version: 1.0.0
#Script Owner: He ,Haibo
#Latest editor: He, Haibo
#Support platform:  Linux OS for redhat and centos.
#Change log:
#Descript:
#
#
###############################################################################################################
export LANG=en_US
osbox=`uname`
RHversion=$(cat /proc/version | sed 's/[^0-9]//g' | cut -b -3)




###打印日志函数
log_info(){
DATE_N=`date "+%Y-%m-%d %H:%M:%S"`
USER_N=`whoami`
echo "${DATE_N} ${USER_N} execute $0 [INFO] $@"  
}


log_error(){
    DATE_N=`date "+%Y-%m-%d %H:%M:%S"`
    USER_N=`whoami`
    echo -e "\033[41;37m ${DATE_N} ${USER_N} execute $0 [ERROR] $@ \033[0m" 
}


fn_log(){
    if [[ $? -eq 0 ]];then
        log_info "$@ sucessed."
        echo -e "\033[32m $@ sucessed. \033[0m"
    else
        log_error "$@ failed."
        echo -e "\033[41;37m $@ failed. \033[0m"
#    exit 1
    fi
}


getOsArch(){
if [[ "$osbox" == "Linux" ]];then
continue
else
echo "Current OS is $osbox,shell is exit now."
echo 0
exit 0
fi
}


getOsCentosOrRedhat(){
cat /proc/version | grep -iE "redhat|centos" > /dev/null
if [[ $? == 0 ]];then
continue
else
echo "Current OS is not centos or redhat."
echo 1
exit 1
fi
}


getOsVerion(){
###判断系统是否为Redhat,如果不是则退出,支持Redhat|Centos 7版本
cat /proc/version | grep -i redhat > /dev/null
if [[ $? == 0 ]];then
if [[ "$RHversion" -ge 310 ]];then 
OSVersion="redhat7"
else
echo "Current Rehat Version will not support."
echo 1
exit 1
fi 
else
if [[ "$RHversion" -ge 310 ]];then 
OSVersion="centos7"
else
echo "Current Rehat Version will not support."
echo 1
exit 1
fi 
fi
}




setFirewalld(){
if [[ $OSVersion == "redhat7" || $OSVersion == "centos7" ]];then
systemctl status firewalld | grep -i running > /dev/null
if [[ $? == 0 ]];then
systemctl stop firewalld && systemctl disable firewalld
else
echo "Firewalld is stopped,Success"
fi
fi
}




setSeLinux(){
cat /etc/selinux/config | grep -w "SELINUX=enforcing" > /dev/null
if [[ $? == 0 ]];then
sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config
setenforce 0
else
echo "Current SeLinux is stopped,Success."
fi
}


rpmInstall(){
###Check yum repolist is right.
    [ $(yum repolist | awk '/repolist/{print$2}' | sed 's/,//') -eq 0 ] && echo 'your yum has problem' && exit 2
    rpmlist=(dapl sg3_utils libnes.x86_64  libmthca.x86_64 libipathverbs.x86_64 libibumad.x86_64 libibmad.x86_64 libcxgb3.x86_64 ibutils.x86_64 libstdc++.so.6 ibsim.x86_64 librdmacm.x86_64 libibcm.x86_64 pam gcc cpp gcc-c++ kernel-devel ksh libstdc++.so.6)
    for i in ${rpmlist[@]} 
    do
        rpm -qa | grep ${i%%.*} &>/dev/null
        [ $? -eq 0 ] || yum install -y $i&>/dev/null
        [ $? -ne 0 ] && echo 'your yum cannot install '$i && yum_right=3
    done
        [ $yum_right ] && exit 3
}






main(){
getOsArch
getOsCentosOrRedhat
getOsVerion
setFirewalld
setSeLinux
}




main

阅读(824) | 评论(0) | 转发(0) |
0

上一篇:JBoss7 局域网无法访问 解决方法

下一篇:没有了

给主人留下些什么吧!~~