自动部署器,即按照给定的文件所在路径通过rsync进行copy到除了本机外的其他机器上
原代码如下:
#!/bin/sh #author :zhangmingwei 20200324 #cmd e.g: deploy ~/app/zookeeper #echo $* arg=( $@ ) #cnt=$# #for((i=0;i<$cnt;i++)) #do # echo ${arg[i]} #done hos1=$(hostname) argcnt=$# ophos=${arg[$((argcnt-1))]} #操作主机 if [ $argcnt -lt 1 ];then echo "your input's args is less than 1,please try input agin!" exit fi hts=(01 02 03) pre=hadoop user=$pre xcmd="$@ file="$1" #pwd #echo "........$file" #ls -lh "$file" pth=$(cd `dirname $file`;pwd) fl=$(basename $file) #echo $pth...$fl... for((i=0;i<${#hts[@]};i++)) do h=${hts[i]} hos=$pre$h if [ "$hos"x != "$hos1"x ];then echo "$hos" #ssh ${user}@$hos " $xcmd " #scp -r $pth/$fl ${user}@$hos:$pth rsync -avzhe ssh --progress $pth/$fl ${user}@$hos:$pth fi #换成本机shell执行有bug done