shell 批量同步

批量同步脚本

#!/bin/bash
#lijunmin 20171124
#批量同步脚本

flush()
{
if [ ! -f rsync.list ];then
	echo -e "\033[31mPlease Create rsync.list Files,The rsync.list contents as follows: \033[0m"
cat <rsync.list.swp
	COUNT=`cat rsync.list.swp |wc -l`
	NUM=0
while ((${NUM} < $COUNT))
do
	NUM=`expr $NUM + 1`
	Line=`sed -n "${NUM}P" rsync.list.swp`
	SRC=`echo $Line |awk '{print $2}'`
	DES=`echo $Line |awk '{print $3}'`
	IP=`echo $Line |awk '{print $1}'`
	rsync -aP --delete ${SRC}/ root@${IP}:${DES}/
done
}

restart()
{
	rm -fr restart.list.swp; cat rsync.list |grep -v "#" >>restart.list.swp
        COUNT=`cat restart.list.swp |wc -l`
        NUM=0
while ((${NUM} < $COUNT))
do
        NUM=`expr $NUM + 1`
        Line=`sed -n "${NUM}P" restart.list.swp`
        Command=`echo $Line |awk '{print $2}'`
        IP=`echo $Line |awk '{print $1}'`
        ssh -l root $IP "$Command;echo -e '---------------------------------\nThe $IP Exec Command : sh $Command success!'"
done
}
case $1 in
	flush)
	flush
	;;
	restart)
	restart
	;;
	*)
	echo -e "\033[31mUsage: $0 command, example{flush | restart} \033[0m"
	;;
esac

 

你可能感兴趣的:(shell)