脚本实例:
判断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