实例脚本,判断是否加入开机自启动,服务状态、脚本规范

脚本实例:

  • 判断ntpd服务是否加入开机自启动


  • #!/bin/bash
    #Output:
    #Resultmustexactlyequalto"3:on,5:on|enable"
    #
    #Otheroutputisnon-compliant.
    
    #ConfirmOsversion
    unsetoS_VERSION
    
    uname-r|grepel5>/dev/null&&OS_VERSION=el5
    uname-r|grepel6>/dev/null&&OS_VERSION=el6
    uname-r|grepel7>/dev/null&&OS_VERSION=el7
    
    #Checkntpautostartonrhel5andrhel6
    functionntp_boot_start()
    {
    localLANG
    localret
    
    LANG="en_US.UTF-8"
    ret=$(chkconfig--listntpd2>/dev/null|awk'{print$5","$7}')
    
    	if["$ret"=""];then
    		ntp_auto=false
    		echo"$ntp_auto"
    
    	elif["$ret"!=""-a"$ret"!="3:on,5:on"];then
    #		echo"$ret"
    #echo"Check[ntpdautostart]...Failed"
    		ntp_auto=false
    		echo"$ntp_auto"
    
    	else
    #		echo"$ret"
    		ntp_auto=true
    		echo"$ntp_auto"
    	fi
    }
    
    #Checkchronyautostartonrhel7
    functionchrony_boot_start()
    {
    localLANG
    localret
    
    LANG="en_US.UTF-8"
    ret=$(systemctlis-enabledchronyd.service2>/dev/null)
    
    	if["$ret"=""];then
    		ntp_auto=false
    		echo"$ntp_auto"
    	elif["$ret"!=""-a"$ret"!="enabled"];then
    		ntp_auto=false
    		echo"$ntp_auto"
    #echo"Changemethod:"
    		#echo"systemctlenablechronyd.service"
    	else
    		ntp_auto=true
    		echo"$ntp_auto"
    	fi
    }
    
    #Begincheck
    if["$OS_VERSION"="el5"-o"$OS_VERSION"="el6"];then
    ntp_boot_start
    elif["$OS_VERSION"="el7"];then
    chrony_boot_start
    fi


  • 判断服务状态


  • #!/bin/bash
    #Output:
    #Atthistime,itmustexactlyequalto"UP".
    #
    #Otheroutputisnon-compliant.
    
    #ConfirmOsversion
    unsetoS_VERSION
    
    uname-r|grepel5>/dev/null&&OS_VERSION=el5
    uname-r|grepel6>/dev/null&&OS_VERSION=el6
    uname-r|grepel7>/dev/null&&OS_VERSION=el7
    
    #Begincheck
    if["$OS_VERSION"="el5"-o"$OS_VERSION"="el6"];then
    pidofntpd&>/dev/null
    if[$?-ne0];then
    		ntpd_service_status=flase
    echo"ntpd_service_status$ntpd_service_status"
    #echo"DOWN"
    #echo"Check[ntpservicestatus]...Failed"
    #echo"Changemethod:"
    #echo"servicentpdstart"
    else
    		ntpd_service_status=true
    echo"ntpd_service_status$ntpd_service_status"
    #echo"UP"
    fi
    elif["$OS_VERSION"="el7"];then
    pidofchronyd&>/dev/null
    if[$?-ne0];then
    		ntpd_service_status=flase
    echo"ntpd_service_status$ntpd_service_status"
    #echo"DOWN"
    #echo"Check[chronyservicestatus]...Failed"
    #echo"Changemethod:"
    #echo"systemctlstartchronyd.service"
    else
    		ntpd_service_status=true
    echo"ntpd_service_status$ntpd_service_status"
    #echo"UP"
    fi
    fi

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...