加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 17:07:41 所属栏目:安全 来源:网络整理
导读:脚本实例: 判断ntpd服务是否加入开机自启动 #!/bin/bash#Output:#Resultmustexactlyequalto"3:on,5:on|enable"##Otheroutputisnon-compliant.#ConfirmOSVersionunsetOS_VERSIONuname-r|grepel5/dev/nullOS_VERSION=el5uname-r|grepel6/dev/nullOS_VERSION=e

脚本实例:

  • 判断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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读