Shell脚本实现Centos相关配置0.3版本

增加远程备份Java ,tomcat,本地环境功能, ,待完善

github地址:https://github.com/LandStart/LinuxShell.git

#=======================================================================
# File Name: centosStartconfig.sh														
# Author: land
# Created Time: 2019-12-4 09:22:09 PM CST
#=======================================================================
#!/bin/zsh
PATH=/home/edison/bin:/home/edison/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/work/tools/gcc-3.4.5-glibc-2.3.6/bin
export PATH
echo "Before operating....................................."

mustCommandList=("ifconfig" "wget" "git" "figlet" "vim")
for i in ${mustCommandList[@]}
do
	if ! [ -x "$(command -v $i)" ]; then
    	echo 'checking the : '$i' is not installed...,prepared to install...' >&2
    	`sudo yum install $i`
	else
		echo ${i} " has  installed."
	fi
done

echo "===================================================="
echo "= your os is :" `uname`"                               ="
echo "= current time is : " `date`                    "  ="
echo "===================================================="
figlet Lad_DDD
echo "please select your number : 0) exit programer "
echo "please select your number : 1) config static ipAddress "
echo "please select your number : 2) config hostname"
echo "please select your number : 3) config ssh without password "
echo "please select your number : 4) config mirro origin"
echo "please select your number : 5) backup database for mysql"
echo "please select your number : 6) programing and environmnet to backup"

while true 
do
	read -p "input the number :" SerialNumber	
	case $SerialNumber in
	1) echo "start config static ipAddress"
	   sed -i 's/dhcp/static/g' ifcfg-eth0
	   sed -i 's/ONBOOT=no/ONBOOT=yes/g' ifcfg-eth0
  	   grepip=`grep 'IPADDR' ifcfg-eth0`
	   if [ $? -ne 0 ]
 	    then
    	   	sed -i '$a\IPADDR=192.168.241.100' ifcfg-eth0
	   fi
	   grepnet=`grep 'NETMASK' ifcfg-eth0`
	   if [ $? -ne 0 ]
 	    then
    		sed -i '$a\NETMASK=255.255.255.0' ifcfg-eth0
	   fi
	   grepgate=`grep 'GATEWAY' ifcfg-eth0`
	   if [ $? -ne 0 ]
 	    then
    	        sed -i '$a\GATEWAY=192.168.241.2' ifcfg-eth0
	   fi
           restartnetwork=`sudo ervice network restart`
	;;
	2)echo "start config hostname"
	  read -p "config the hostname: " -t 100 hostname
	  read -p "config the hostnameipaddress: " -t 100 ip
	  echo -e "$hostname"
	  echo $ip
	  grepip=`grep $ip /home/land/hosts`
	  if [ $? -ne 0 ]
 	   then
    	  	sed -i '$a\'$ip /home/land/hosts
    	  grephost=`grep "$hostname" /home/land/hosts`
    	  if [ $? -ne 0 ]
     	   then 
        	sed -i 's/'$ip'/&'" $hostname "'/g' /home/land/hosts
    	  fi
	  else
   		sed -i 's/'$ip'/&'" $hostname "'/g' /home/land/hosts
	  fi
	;;
	3)echo "start ssh without password"
	  finstallssh=`ssh`
	  if [ $? -ne 0 ]
 	   then
   	  	`ssh-keygen`
	  else
       		`sudo yum install ssh`
        	`ssh-keygen`
	  fi
	  read -p "please input use need to access with no use the password: " user
	  read -p "please input ipAddress need to access witiiih no use the password: " server
		`ssh-copy-id -i ~/.ssh/id_rsa.pub $user@$server`
	;;
	0)
	 break
	;;
	4)
      `sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak`
	  `sudo /etc/yum.repos.d/`
	  `sudo wget http://mirrors.163.com/.help/CentOS7-Base-163.repo`	
	;;
	5)
	echo "=============================================================================="
	echo " if your sql user no permisson , please modify the sqluer and sqlpasswd config"
	echo "=============================================================================="
 	read -p "please accure save location want to save : " savelocation
      if [ -e $savelocatioin ]
       then
                sudo mkdir -p $savelocation
          fi
      echo "Today is `date +%Y-%m-%d` start to backup......"
      today=`date +%Y-%m-%d`
      databaselocation=`ls /var/lib/mysql/`
      for db_name in $databaselocation
        do
            if test ! -e $savelocation/$db_name.$today
             then
                echo "create conditon for  backup the   ${db_name}...."
                if [ -d ${db_name} ]
                 then
                    sudo mkdir -p $savalocation/$db_name
                    sudo chmod -R 774 $savelocation/$db_name
                fi
            fi
        echo "start backup the database "
      mysqldump=`which mysqldump`
      sqluer=root
          sqlpasswd=root
      `sudo mysqldump -u $sqluser -p $sqlpasswd -R $db_name >> $savelocation/$db_name`
      done
	;;
	6)
		echo "start back the enviromnet and programing ......"
		read -p "please input the remote server host to backup : " server
		read -p "please input the remote DEST to backup : " synrcserver
		read -p "please input the remote user to back : " user
		echo "prepared to starting ...  `date +%Y-%M-%d`"
		echo "If not to config the JAVA_HOME ,please tell the java installed path ,else not to input : " javapath
		echo "--------------------------------------------------------------------------------------------------------"
		echo "If not to config the TOMCAT_HOME ,please tell the tomcat installed path ,else not to input : " tomcatpath
		echo "--------------------------------------------------------------------------------------------------------"
		echo " straring sync the system environmnet -------->"
		rsync -atuvzrpLH /etc/hosts $user@${server}::${synrcserver}
		rsync -autvzrpLH /etc/porfile $user@${server}::${synrcserver}

		echo " straring sync the java environmnet -------->"
		if [ $javapath -eq "" ]
		then
			javapath=$JAVA_HOME
		fi
		rsync -autvzrpLH $javapath $user@${server}::${synrcserver}

		echo " starting sync the tomcat environment ------->"
		if [ $tomcatpath -eq ""]
		then
			tomcatpath=$TOMCAT_HOME
		fi
		rsync -autvzrpLH $tomcatpaht $user@${server}::${synrcserver}
			;;
	*)echo 'plase input the correct select'
	    ;;
	esac
 done





 

 

如有问题,敬请指出,谢谢,与君共勉 。

Vim模板配置参考:https://blog.csdn.net/amoscykl/article/details/80616688

rsync命令参考 :https://www.cnblogs.com/piaozhe116/p/5728749.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值