1. 程式人生 > >OGG運維優化腳本(十二)-信息同步類--信息上傳

OGG運維優化腳本(十二)-信息同步類--信息上傳

og

文件: upload.sh

路徑:$HOME/ggscript/ggupload

功能:該腳本不會直接使用,為滿足其他腳本進行信息上傳而設計,在腳本內直接調用上傳相應的文件信息

他會讀取系統信息配置文件sysinfo內的系統配置信息

範例

[detest#]

Ip-MTMyLjEyMS4xMDEuODYK

UserName-Z2dzCg==

PassWord-Z2dzxxxxxx

Port-MjIK

path-L2RhdGExL2dncy9nZ3NlcnZlci9kaXJkZWYK

[#detest]

以上信息以base64進行加密,保證信息安全,獲取IP 用戶名,密碼,以及端口路徑

並將相應的文件下發至對應的機器

#!/bin/bash
if [ $# -eq 0 ]; then
        echo "info host file checkf"
        exit 2
fi

 
if [ $# -eq 1 ]; then
        echo "info host file checkf"
        exit 2
fi

if [ $# -eq 1 ]; then
        echo "info host file checkf"
        exit 2
fi
host=$1
file=$2
checkf=$3
cd $HOME/ggscript/ggupload

#sed  ‘/"$host"/,/5/p‘ $checkf > infotmp
cat $HOME/ggscript/ggupload/$checkf | awk ‘/‘$host‘#/,/#‘$host‘/{if(i>1)print x;x=$0;i++}‘ > $HOME/ggscript/ggupload/infotmp

ip=`cat $HOME/ggscript/ggupload/infotmp|grep -w "Ip"|cut -d "-" -f 2`
pw=`cat $HOME/ggscript/ggupload/infotmp|grep -w "PassWord"|cut -d "-" -f 2`
port=`cat $HOME/ggscript/ggupload/infotmp|grep -w "Port"|cut -d "-" -f 2`
us=`cat $HOME/ggscript/ggupload/infotmp|grep -w "UserName"|cut -d "-" -f 2`
path=`cat $HOME/ggscript/ggupload/infotmp|grep -w "path"|cut -d "-" -f 2`

echo "code"
echo "ip=$ip"
echo "pw=$pw"
echo "port=$port"
echo "user= $us"
echo "path=$path"


echo $ip > tmp

perl -MMIME::Base64 -ne ‘print decode_base64($_)‘ <  tmp > out
ip=`cat out`

echo $pw > tmp
perl -MMIME::Base64 -ne ‘print decode_base64($_)‘ <  tmp > out
pw=`cat out`

echo $port > tmp
perl -MMIME::Base64 -ne ‘print decode_base64($_)‘ <  tmp > out
port=`cat out`

echo $us > tmp
perl -MMIME::Base64 -ne ‘print decode_base64($_)‘ <  tmp > out
us=`cat out`

echo $path > tmp
perl -MMIME::Base64 -ne ‘print decode_base64($_)‘ <  tmp > out
path=`cat out`


#echo "decode"
#echo "ip=$ip"
#echo "pw=$pw"
#echo "port=$port"
#echo "user=$us"
#echo "path=$path"


while [ ${#port} -le 1 ]
do
	port=22
done

#echo $ip $pw $port $path
expect -c "
  spawn scp -r -P $port $file $us@$ip:$path
  expect {
    \"*assword\" {set timeout 300; send \"$pw\r\";}
    \"yes/no\" {send \"yes\r\"; exp_continue;}
  }
expect eof"


本文出自 “netsman” 博客,請務必保留此出處http://netsman.blog.51cto.com/5750076/1939643

OGG運維優化腳本(十二)-信息同步類--信息上傳