第二个shell脚本实例

  |   0 评论   |   0 浏览
#!/bin/bash
set +x

thisip=$(ifconfig eth0 | grep inet | grep -v inet6 | awk -F " " '{print$2}')
iplistDir="/usr/local/iplist.txt"
destpath="/usr/local"
destfile="telescope_linux_amd64.tar.gz"

trim()
{
    trimmed=$1
    trimmed=${trimmed%% }
    trimmed=${trimmed## }


    echo $trimmed
}


conf=$(cat $destpath/telescope/bin/conf.json)

cat $iplistDir | while read ipid
do
   ip=$(echo $ipid | awk -F ":" '{print$1}')
   idp=$(echo $ipid | awk -F ":" '{print$2}')
   if [ $ip != "" -a $thisip != $ip ]; then
      id=$(echo $idp | awk -F " " '{print$1}')
      echo $ip:$id
      password=$(echo $idp | awk -F " " '{print$2}')
      conf=$(sed "2c \"InstanceId\": \"$id\"," $destpath/telescope/bin/conf.json)
      conf=${conf//'"'/'\"'}
      cmdscp="scp -o StrictHostKeyChecking=no $destpath/$destfile root@$ip:/$destpath"
      cmd="cd /usr/local && tar -xvf $destfile && cd telescope_linux_amd64 && chmod 700 install.sh && ./install.sh && cd ../telescope/bin && echo \"$conf\" > conf.json && service telescoped restart"
      cmdssh="ssh -o StrictHostKeyChecking=no root@$ip '$cmd' "
      if [ -z $password ]; then
          password=$1
      fi
	  temp=$(command -v python 2>&1 || { echo <&1 "py3";}) # command -v python 2>&1,判断python命令是否存在
      echo $temp
      if [ "$temp" = "py3" ]; then
          python3 pexpectSpawn3.py "$cmdscp" $password
	      python3 pexpectSpawn3.py "$cmdssh" $password &
	      echo $ip
      else
          echo $password | python pexpectSpawn.py "$cmdscp"
	      echo $password | python pexpectSpawn.py "$cmdssh" && echo "End if install agent: $ip" &
	      echo $ip
      fi
   fi
done


标题:第二个shell脚本实例
作者:SmiteLi
地址:https://smite.site/articles/2020/02/23/1582421088601.html