shell习题-关闭服务


在centos6系统里,我们可以使用ntsysv关闭不需要开机启动的服务,当然也可以使用chkconfig工具来实现。

写一个shell脚本,用chkconfig工具把不常用的服务关闭。脚本需要写成交互式的,需要我们给它提供关闭的服务名字。

 

参考答案:

#!/bin/bash

LANG=en
c="1"

while [ ! $c == "q" ]
do
    echo -e "\033[35mPlease chose a service to close from this list: \033[0m"
    chkconfig --list |awk '/3:on/ {print $1}'
    read -p "Which service to close: " s
    chkconfig $s off
    service $s stop
    read -p  "If you want's to quit this program, tab "q", or tab "Ctrl c": " c
done