#! /bin/bash res=0 from=$1 to=$2 shift shift files="$@" if test -z "$from" -o -z "$to" -o -z "$files" then echo "Usage: $0 (file)*" echo "example: $0 server1 server2 /usr/bin/myapp" exit 1 fi read -s -p "Enter Password: " sudopassword echo "" temp1=$(mktemp) temp2=$(mktemp) (echo "$sudopassword";echo "$sudopassword"|ssh $from sudo -S tar c -P -C / $files 2>$temp1)|ssh $to sudo -S tar x -v -P -C / 2>$temp2 sourceres=${PIPESTATUS[0]} if [ $? -ne 0 -o $sourceres -ne 0 ] then echo "Failure!" >&2 echo "$from output:" >&2 cat $temp1 >&2 echo "" >&2 echo "$to output:" >&2 cat $temp2 >&2 res=1 fi rm $temp1 $temp2 exit $res