#!/bin/sh #Auto change server files #liudong 2016-3-21 if [ ! -f ip.txt ];then echo -e "\033[31mplease create ip.txt files,the ip.txt contents as follows: \033[0m" cat << EOF 111.206.164.196 111.206.164.197 111.206.164.198 EOF exit fi if [ -z "$1" ];then echo -e "\033[31mUsage: $0 command,Example{src_Files|sre_Dir Des_dir} \033[0m" exit fi count=`cat ip.txt |wc -l` rm -rf ip.txt.swp i=0 while ((i< $count)) do i=`expr $i + 1` echo $i sed "${i}s/^/&${i} /g" ip.txt >> ip.txt.swp IP=`awk -v I="${i}" '{if(I==$1)print $2}' ip.txt.swp` echo $IP scp -r -P22 $1 root@${IP}:$2 done