首页 > 系统相关 >shell脚本模板

shell脚本模板

时间:2023-04-05 17:34:24浏览次数:44  
标签:脚本 bin shell firewalld echo systemctl main 模板

shell脚本模板

#!/bin/sh

. /etc/rc.d/init.d/functions
export LANG=zh_CN.UTF-8

#一级菜单
menu1()
{
clear
cat <<eof
----------------------------------------
|#         CentOS7.9优化脚本          #|
----------------------------------------

1. 一键优化
2. 自定义优化
3. 退出

EOF
read -p "please enter your choice[1-3]:" num1
}


#二级菜单
menu2()
{
 clear
 cat << eof
----------------------------------------
|#   Please Enter Your Choice:[0-9]   #|
----------------------------------------

1. 关闭selinux
2. 关闭firewalld

0.Back

EOF
 read -p "please enter your choice[0-9]:" num2

}

#1.关闭selinux
selinuxset()
{
 echo ''
 sleep 1
}

#2.关闭firewalld
firewalldset()
{
 echo ''
 sleep 1
}



#控制函数
main()
{
 menu1
 case $num1 in
  1)
   selinuxset
   firewalldset
   ;;
  2)
   menu2
   case $num2 in
                  1)
                    selinuxset
                    ;;
                  2)
                    firewalldset
                    ;;
                  0)
                    main
                    ;;
                  *)
                    echo 'Please select a number from [0-9].'
                    ;;
                  esac
                  ;;
  0)
   exit
   ;;
  *)
   echo 'Err:Please select a number from [1-3].'
   sleep 3
   main
   ;;
 esac
}

main $*

系统优化脚本例子

系统优化脚本例子
#!/bin/sh

. /etc/rc.d/init.d/functions
export LANG=zh_CN.UTF-8

#一级菜单
menu1()
{
clear
cat <<eof
----------------------------------------
|#         CentOS7.9优化脚本          #|
----------------------------------------

1. 一键优化
2. 自定义优化
3. 退出

EOF
read -p "please enter your choice[1-3]:" num1
}


#二级菜单
menu2()
{
 clear
 cat << eof
----------------------------------------
|#   Please Enter Your Choice:[0-9]   #|
----------------------------------------

1. 关闭selinux
2. 关闭firewalld

0.Back

EOF
 read -p "please enter your choice[0-9]:" num2

}

#1.关闭selinux
selinuxset()
{
 selinux_status=`grep "SELINUX=disabled" /etc/sysconfig/selinux | wc -l`
 echo "========================禁用SELINUX========================"
 if [ $selinux_status -eq 0 ];then
  sed  -i "s#SELINUX=enforcing#SELINUX=disabled#g" /etc/sysconfig/selinux
  setenforce 0
  echo '#grep SELINUX=disabled /etc/sysconfig/selinux'
  grep SELINUX=disabled /etc/sysconfig/selinux
  echo '#getenforce'
  getenforce
 else
  echo 'SELINUX already disabled'
  echo '#grep SELINUX=disabled /etc/sysconfig/selinux'
                grep SELINUX=disabled /etc/sysconfig/selinux
                echo '#getenforce'
                getenforce
 fi
  action "Disabled SELINUX" /bin/true
 echo "==========================================================="
 echo ''
 sleep 1
}

#2.关闭firewalld
firewalldset()
{
 echo "=======================禁用firewalld========================"
 systemctl stop firewalld.service &> /dev/null
 echo '#firewall-cmd  --state'
 firewall-cmd  --state
 systemctl disable firewalld.service &> /dev/null
 echo '#systemctl list-unit-files | grep firewalld'
 systemctl list-unit-files | grep firewalld
 action "Disable firewalld" /bin/true
 echo "==========================================================="
 echo ''
 sleep 1
}



#控制函数
main()
{
 menu1
 case $num1 in
  1)
   selinuxset
   firewalldset
   ;;
  2)
   menu2
   case $num2 in
                  1)
                    selinuxset
                    ;;
                  2)
                    firewalldset
                    ;;
                  0)
                    main
                    ;;
                  *)
                    echo 'Please select a number from [0-9].'
                    ;;
                  esac
                  ;;
  0)
   exit
   ;;
  *)
   echo 'Err:Please select a number from [1-3].'
   sleep 3
   main
   ;;
 esac
}

main $*

标签:脚本,bin,shell,firewalld,echo,systemctl,main,模板
From: https://www.cnblogs.com/ssc9879/p/17289652.html

相关文章

  • shell常用脚本
    sed使用sed来为函数统一添加宏包含sed-i's/dataTypeCast\(.*\);/FUNC_CALL\(dataTypeCast\1\);/g'file会对dataTypeCast函数添加FUNC_CALL包含。dataTypeCast(abcd);==>FUNC_CALL(dataTypeCast(abcd));......
  • VMware安装CentOS7并用FinalShell连接
    时间:2023/4/5作者:Nhenk目录1.下载2.安装3.安装虚拟机3.1CentOS7.6下载3.2CentOS7.6安装3.3CentOS7.6的安装配置3.4CentOS7.6的网络配置3.4.1自动获取IP3.5FinalShell连接CentOS7.61.下载VMware2.安装因为我之前安装了docker而开启了Hyper-V,所......
  • 在windows下通过xshell来实现跳板机配置pycharm环境和xftp文件访问
    xshell实现跳板机先使用xshell实现跳板机,并将对应的跳板机窗口打开。跳板机使用xshell的隧道功能实现,选择作为中转的服务器B的属性。选择隧道选择添加侦听端口为本机A的,后面通过localhost:7777进行访问。这个端口可以自己设置不同的。目标主机就是通过服务器B作为跳板机,要......
  • java——maven——idea使用模板(骨架)创建maven工程——webapp(重点)
    黑马模板:                  本地:         ......
  • python3里面实现将日志文件写入当前脚本运行的文本中
    在Python3中,可以使用logging模块来实现将日志写入本地文本文件中。下面是一个简单的示例代码:importlogging#配置logging模块logging.basicConfig(level=logging.DEBUG,filename='example.log',format='%(asctime)s%(leve......
  • Redis事务与Lua脚本
    Redis的事务没办法保证一致性,使用Lua脚本也不能保证。Lua脚本能保证一致性,而且比redis的事务实习要简洁健壮。转载:https://maimai.cn/article/detail?fid=1538576512&efid=SQ3XsywteU9lIxil766Lxw......
  • 浏览器划词翻译脚本iTranslator
    iTranslator划词翻译安装,首先浏览器要先安装暴力猴插件,搜索iTranslator安装即可使用,光标选择页面上的词语,按下T键就可以翻译,按下Y键就可以撤销翻译缺点:输入框不能直接翻译,要选择里的打开翻译才会有个输入框翻译......
  • origin迁移用户主题和模板
    1、用户自定义的文件位于:C:\Users\******\Documents\OriginLab\UserFiles我们拷贝这个文件夹到新的电脑上替换UserFiles文件夹即可2、替换完成后,主题一般会自动更新,但是绘图模板需要手动添加进去。       3、origin的使用套路一般是,先创建模板,然后创建主题,后面......
  • KEIL——添加自己的注释模板
    【系列专栏】:博主结合工作实践输出的,解决实际问题的专栏,朋友们看过来!《QT开发实战》《嵌入式通用开发实战》《从0到1学习嵌入式Linux开发》《Android开发实战》《实用硬件方案设计》 长期持续带来更多案例与技术文章分享;欢迎商业项目咨询,10年+软硬全栈内功,助力解决您的尊贵需求。......
  • istio shell
    #!/bin/sh#CopyrightIstioAuthors##LicensedundertheApacheLicense,Version2.0(the"License");#youmaynotusethisfileexceptincompliancewiththeLicense.#YoumayobtainacopyoftheLicenseat##http://www.apache.org/li......