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

增加抓取静态网站的超链接功能,1.0版本, ,功能待完善

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"
echo "please select your number : 7) patch the static page "
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}
			;;
	7)
		read -p "please input the html url : " hp
		curl $hp > index.html
		alist=`grep -ohr -E "(https?|ftp|file)://[A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]"  index.html`

		echo "save the url list to file urllist / readList.txt: "
		mkdir urllist
		touch urllist/readList.txt
		touch urllist/readedList.txt

		array=(${alist//" "/ })

		echo $array >> urllist/readList.txt

		for var in ${array[@]}
		do
			isexist=`grep $var urllist/readedList.txt`
			if [ $? -eq 0 ]
			then
                continue
			else
                echo "prepared loading the url:$var"
                echo "$var" >> urllist/readedList.txt

                ifexist=`echo "$var" | grep -ohr -E "[*.jpg|*.png|*.gif|*.txt]"`
                if [ $? -eq 0 ]
                then
                        continue
                else
                        newpage=curl $var
                        aalist=`grep -ohr -E "(https?|ftp|file)://[A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]"  $newpage`
                    
						echo $aalist>>index.html
  
				fi
			fi
		done	
		;;
	*)echo 'plase input the correct select'
	    ;;
	esac
 done





 

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

 

 

你可能感兴趣的:(Linux,Shell小例子)