首頁  >  文章  >  系統教程  >  SELinux輕鬆一鍵開啟與停用腳本

SELinux輕鬆一鍵開啟與停用腳本

WBOY
WBOY原創
2024-06-24 20:04:04307瀏覽

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中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn