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 $*