码迷,mamicode.com
首页 > 其他好文 > 详细

基础脚本

时间:2020-08-17 16:36:56      阅读:56      评论:0      收藏:0      [点我收藏+]

标签:sed   hit   disabled   sorry   input   mail   标识   emctl   火墙   

#!/bin/bash
#Author:jack wangbr/>#Work:安装初始化
#Phone-num:1888888888
#QQ-mail:2891133555@qq.com
#Date:2020-08-12
#Version:2.0
#***
RED="\033[5;31m"
GREEN="\033[32m"
WHITE="\033[37m"
YELLOW="\033[5;33m"
END="\033[0m"

颜色标识

echo -e "${WHITE}本程序仅为centos{6,7,8}版本提供如下服务:
\n1,关闭selinux;
\n2,关闭防火墙;
\n3,修改网卡名;
\n4,修改主机名;
\n5,安装基础软件包;
\n6,q|Q退出。
\n${END}"

D_SE() {
egrep "^SELINUX=Enforcing" /etc/selinux/config
if [ $? -ge 0 ];then
sed -i "/^SELINUX=/s/Enforcing/disabled/g" /etc/selinux/config
fi
echo -e "${GREEN}SELINUX is disabled now!${END}\n"
}
#关闭selinux

D_FI() {
Version=$(echo uname -r | awk -F "." ‘{print $4}‘)
case $Version in
el6)
chkconfig iptables off
echo -e "${GREEN}Iptables is disabled now!${END}\n"
;;
el[7,8])
systemctl stop firewalld
systemctl disable firewalld
echo -e "${GREEN}Firewalld is disabled now!${END}\n"
;;
*)
echo -e "${YELLOW}Sorry,service for centos{6,7,8} now!${END}\n"
esac
}
#关闭防火墙

C_NET() {
egrep "^(GRUB_CMDLINE_LINUX=)" /etc/default/grub |grep "net.ifnames=0"
if [ $? -ge 0 ];then
sed -Ei ‘/GRUB_CMDLINE_LINUX=/s/(.*)(")/\1 net.ifnames=0\2/g‘ /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
fi
echo -e "${GREEN}网卡名已修改!${END}"
}
#修改网卡名

C_HOST() {
read -p "Please input your hostname :" HOST
hostnamectl set-hostname ${HOST}
echo -e "${GREEN}Your hostname is hostname now!${END}\n\n"
}
#修改主机名

I_SO() {
yum install -y vim tree ntp lrzsz &> /dev/null
echo -e "${YELLOW}已安装如下软件:${END}"
yum list installed | egrep "vim|tree|ntp|lrzsz"
echo -e "${GREEN}您可以选择继续安装软件或退出$END"

for ((;;))
do
read -p "You can choose i/I to 【install】 or q/Q to 【exit】 :" comd
case ${comd} in
i|I)
    read -p "Please input name :" Pack
    yum list installed | grep ${Pack}
    if [ $? -eq 0 ];then
        echo -e "${GREEN}Already installed!${END}"
    else
        yum install -y ${Pack}
    fi
;;
q|Q)
    break   
;;
*)
    echo -e "${RED}Please check you input!${END}"
esac
done

}
#安装基础软件包

for ((;;));do
read -p "请选择执行操作序号:" NUM
case $NUM in
1)
D_SE
;;
2)
D_FI
;;
3)
C_NET
;;
4)
C_HOST
;;
5)

    I_SO
;;
6|q|Q)
    break
;;
*)
    echo  -e "${RED}Wrong number!!!${END}"
esac    

done

基础脚本

标签:sed   hit   disabled   sorry   input   mail   标识   emctl   火墙   

原文地址:https://blog.51cto.com/13434656/2520011

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!