实例脚本,判断是否加入开机自启动,服务状态、脚本规范
2017-08-07 21:41
435 查看
脚本实例:
判断ntpd服务是否加入开机自启动
判断服务状态
判断ntpd服务是否加入开机自启动
#!/bin/bash # Output: # Result must exactly equal to "3:on,5:on|enable" # # Other output is non-compliant. # Confirm OS Version unset OS_VERSION uname -r | grep el5 > /dev/null && OS_VERSION=el5 uname -r | grep el6 > /dev/null && OS_VERSION=el6 uname -r | grep el7 > /dev/null && OS_VERSION=el7 # Check ntp auto start on rhel5 and rhel6 function ntp_boot_start () { local LANG local ret LANG="en_US.UTF-8" ret=$(chkconfig --list ntpd 2>/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 [ntpd auto start]... FAILED" ntp_auto=false echo "$ntp_auto" else # echo "$ret" ntp_auto=true echo "$ntp_auto" fi } # Check chrony auto start on rhel7 function chrony_boot_start () { local LANG local ret LANG="en_US.UTF-8" ret=$(systemctl is-enabled chronyd.service 2>/dev/null) if [ "$ret" = "" ]; then ntp_auto=false echo "$ntp_auto" elif [ "$ret" != "" -a "$ret" != "enabled" ];then ntp_auto=false echo "$ntp_auto" #echo "Change method:" #echo "systemctl enable chronyd.service" else ntp_auto=true echo "$ntp_auto" fi } #Begin check if [ "$OS_VERSION" = "el5" -o "$OS_VERSION" = "el6" ];then ntp_boot_start elif [ "$OS_VERSION" = "el7" ];then chrony_boot_start fi
判断服务状态
#!/bin/bash # Output: # At this time, it must exactly equal to "UP". # # Other output is non-compliant. # Confirm OS Version unset OS_VERSION uname -r | grep el5 > /dev/null && OS_VERSION=el5 uname -r | grep el6 > /dev/null && OS_VERSION=el6 uname -r | grep el7 > /dev/null && OS_VERSION=el7 # Begin check if [ "$OS_VERSION" = "el5" -o "$OS_VERSION" = "el6" ];then pidof ntpd &> /dev/null if [ $? -ne 0 ];then ntpd_service_status=flase echo "ntpd_service_status $ntpd_service_status" # echo "DOWN" # echo "Check [ntp service status]... FAILED" #echo "Change method:" #echo "service ntpd start" else ntpd_service_status=true echo "ntpd_service_status $ntpd_service_status" # echo "UP" fi elif [ "$OS_VERSION" = "el7" ];then pidof chronyd &> /dev/null if [ $? -ne 0 ];then ntpd_service_status=flase echo "ntpd_service_status $ntpd_service_status" # echo "DOWN" # echo "Check [chrony service status]... FAILED" #echo "Change method:" #echo "systemctl start chronyd.service" else ntpd_service_status=true echo "ntpd_service_status $ntpd_service_status" # echo "UP" fi fi
相关文章推荐
- 实例脚本,判断是否加入开机自启动,服务状态、脚本规范
- Oracle之 服务启动&停止脚本与开机自启动(单实例)
- Linux Oracle服务启动&停止脚本与开机自启动
- 判断IP是否规范并添加或修改IP地址的shell脚本
- android判断服务是否是运行状态
- nginx加入到系统服务并开机自启动项
- Android----列出设备中所有启动的服务,及判断某个服务是否开启(服务状态)!
- Android判断服务是否运行及定位问题实例分析
- Linux Oracle服务启动&停止脚本与开机自启动
- Linux Oracle服务启动&停止脚本与开机自启动
- Android判断后台服务是否开启的两种方法实例详解
- Linux Oracle服务启动&停止脚本与开机自启动
- windows判断服务状态批处理脚本
- Centos7以普通用户启动zookeeper并加入开机自启动服务
- 【转】Linux Oracle服务启动&停止脚本与开机自启动
- Linux Oracle服务启动&停止脚本与开机自启动
- CentOS Oracle服务启动&停止脚本与开机自启动
- (转)Linux Oracle服务启动&停止脚本与开机自启动
- 判断一个服务是否处于开启状态
- ServiceStatusUtils--判断某一个服务是否是运行状态的工具类