zoukankan      html  css  js  c++  java
  • 跟我学习日常写的shell脚本-设置系统selinux

    设置系统selinux

    #!/bin/bash   
    #  -------------+--------------------   
    # * Filename    :       selinux.sh                         
    # * Date        :       2020-06-15 
    # * Author      :       wangjianxiong           
    # * Description :                       
    #  -------------+--------------------- 
    
    path=/etc/selinux/config
    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

    执行:

    [root@tdh1 ~]# ./set_selinux.sh --help
    ./set_selinux.sh [ enforcing | permissive | disabled  ]
  • 相关阅读:
    BeautifulSoup 安装使用
    用Mediawiki做百科网站资源大参考
    ubutun 下webalizer 分析Apache日志
    网站流量统计系统 phpMyVisites
    mysql的root密码忘记解决方
    mrtg监控网络流量简单配置
    CentOS 6.4下Squid代理服务器的安装与配置,反向代理
    linux 查看文件系统类型
    JAVA多媒体编程入门(图像部分)
    log4net使用具体解释
  • 原文地址:https://www.cnblogs.com/daxiong1314/p/13153892.html
Copyright © 2011-2022 走看看