Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Need help with script to copy code to multiple servers

$
0
0
Hi,

I am new to scripting and i am trying to use below script to copy code to multiple servers and multiple locations on each server. the script is not working or doesnt give any error. Any help is appreciated. basically i want a script to get the code from a location (dir below) and read the serverlist file (it has multiple servers and multiple locations on each server ) and copy code to all those servers and locations mentioned on serverlist file. Please help ...


Code:

#
# Edit desst variable with directory path where you want file to be copied.
#
HOSTS=/opt/serverlist
dir=/usr/newcode/
echo "Are you sure you want to copy $dir to the  standard list of servers"
echo "This may take a while!!"
echo -n "Enter 'y' or 'n':"
read CHOICE
case "$CHOICE" in
        y|yes|Yes) while read line
do
        serverName=echo $line | awk -F':' '{print $1}'
        distLocations = echo $line | awk -F':' '{print $2}'
done
for distLocations in ${distLocations//:/ } ;
do
          scp -rp $dir $serverName:$distLocations
done < $HOSTS
  ;;
        *) echo "wrong entry"
            ;;
esac


here is how my serverlist file looks

Code:

server1;/usr/copycodehere/code1~/usr/copycodehere/code2
server2;/usr/copycodehere/code1~/usr/copycodehere/code2
server3;/usr/copycodehere/code1~/usr/copycodehere/node2


Viewing all articles
Browse latest Browse all 16232

Trending Articles