SELinux轻松一键开启与禁用脚本

WBOY
发布: 2024-06-24 20:04:04
原创
299 人浏览过

SELinux轻松一键开启与禁用脚本

脚本代码

#!/bin/bash  
#  -------------+--------------------   
# * Filename    :       selinux.sh           
# * Revision    :       2.0             
# * Date        :       2017-09-02
# * Author      :       Aubin           
# * Description :                       
#  -------------+---------------------
#       www.shuaiguoxia.com
#

path=/app/selinux
selinux=`sed -rn "/^(SELINUX=).*\$/p" $path`

case $1 in
enforcing|en)

        sed -ri "s@^(SELINUX=).*\$@\1enforcing@g" $path
        if [ $selinux ==  'SELINUX=disabled' ];then
                read -p "SELinux enforcing. you need reboot system ( yes or no ):" input
                [ $input == 'yes' -o $input == 'y' ] && reboot || echo "please Manual operation reboot"
        else
                echo "SELinux enforcing."
        fi
        ;;
permissive|per|pe)
        sed -ri "s@^(SELINUX=).*\$@\1permissive@g" $path
        if [ $selinux == 'SELINUX=disabled' ];then
                read -p "SELinux permissive. you need reboot system ( yes or no ):" input
                [ $input == 'yes' -o $input == 'y'] && reboot || echo "please Manual operation reboot"
        else
                echo "SELINUX permissive"
        fi
        ;;
disabled|dis|di)
        sed -ri "s@^(SELINUX=).*\$@\1disabled@g" $path
        if [ $selinux == 'SELINUX=enforcing' ];then
                 read -p "SELinux permissive. you need reboot system ( yes or no ):" input
                [ $input == 'yes' -o $input == 'y' ] && reboot || echo "please Manual operation reboot"
        else
                echo "SELINUX disabled"
        fi
        ;;
l|a)
        echo `sed -nr 's@(^SELINUX=.*)@\1@p' $path`
        ;;
help|--help)
        echo "$0 [ enforcing | permissive | disabled  ]"
        ;;
*)
        echo "$0 [ enforcing | permissive | disabled  ]"

        ;;
esac
登录后复制

脚本测试
SELinux轻松一键开启与禁用脚本

根据case语句对用户的位置变量(输入的参数)进行判断,进而根据不同的参数实现不同的效果。

SELinux在enforcing状态与disabled状态切换时必须要进行重启才能生效,所以要在脚本中判断用户之前的SELinux的状态是什么样的,询问用户是否进程重启操作系统。

以上是SELinux轻松一键开启与禁用脚本的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:linuxprobe.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!