86.开机自启查看开启关闭脚本

#!/bin/bash
#The script is used to shut down the service process.
#Date 2021-02-07
service_list=/tmp/service_list.txt#定义文本路径
#选择模式开启或者关闭
read -p "Please choose to turn on or off the service automatically.(open|close) " tpye
case $tpye in
        open)
while :
do
        #筛选开机关闭项写入文本
    chkconfig --list 2>/dev/null| awk '$5=="3:off" {print $1}' > $service_list
    echo "The following service processes are off:"
    cat $service_list
                #选择需要开启的服务
        read -p "Please select the service process to be turn on in the list: " select
                #判断输入服务是否存在
        if grep -qw "$select" $service_list;then
                #再次确认是否需要开启
            read -p "Do you want to start up the service process.(y|n) " answer
                case "$answer" in
                        y|Y)
                        chkconfig $select on
                        break
                        ;;
                        n|N)
                        echo "Bye."
                        break
                        ;;
                        *)
                        echo "Please input y or n."
                        continue
                        ;;
                esac
        else
                echo -e "The service process does not in the list.\n"
                continue
        fi
done
#删除文本
[ -f $service_list ] && rm $service_list
;;
        close)
while :
do
    #筛选开机自启项写入文本
    chkconfig --list 2>/dev/null| awk '$5=="3:on" {print $1}' > $service_list
        #查看开机自启项
    echo "The following service processes are on:"
    cat $service_list
                #选择需要关闭的服务
        read -p "Please select the service process to be shut down in the list: " select
                #判断输入的服务是否存在
        if grep -qw "$select" $service_list;then
                #再次确认是否关闭
            read -p "Do you want to shut down the service process.(y|n) " answer 
                case "$answer" in  
                        y|Y) 
                        chkconfig $select off 
                        break 
                        ;; 
                        n|N) 
                        echo "Bye." 
                        break 
                        ;; 
                        *) 
                        echo "Please input y or n." 
                        continue 
                        ;; 
                esac 
        else 
                echo -e "The service process does not in the list.\n" 
                continue 
        fi 
done 
#删除文本
[ -f $service_list ] && rm $service_list 
;; 
        *)               
        echo "Please input open or close." 
        ;; 
esac

猜你喜欢

转载自blog.51cto.com/11594671/2621868
今日推荐