关闭服务

这一生的挚爱 提交于 2019-11-30 04:28:35

题目要求

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

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

参考答案

#!/bin/bash
#这个脚本用来关闭服务
#作者:猿课-阿铭 www.apelearn.com
#日期:2018-12-14

LANG=en

while :
do
    chkconfig --list 2>/dev/null|grep '3:on' |awk '{print $1}' > /tmp/on_sev.txt
    echo -e "\033[32m系统里开启了这些服务: \033[0m"
    cat /tmp/on_sev.txt
    echo
    read -p "Please select a service from this list: " s

    if ! grep -qw "$s" /tmp/on_sev.txt
    then
        echo -e "\033[31m你提供的服务名并未开启.\033[0m"
        continue
    fi
    chkconfig $s off
    break
done

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!