linux - Automate scp website file transfer using a shell script -


i have 3 digital ocean droplets, how automate 1 droplet files 2 droplets, write scp shell script. guys have other suggestions or file transfer between 2 droplets?

#! /usr/bin/env bash  # variables server1user=root server1pswd=killergirls server1ip=123.123.123.123 server1path=/etc/var/html/www/  server2user=root server2pswd=killerboys server2ip=121.121.121.121 server2path=/etc/var/html/www/  echo -e "\n--- first server files transferring now... ---\n" sshpass -p "$server1pswd" scp -r /etc/var/html/www/ server1user@server1ip:$server1path  echo -e "\n--- second server files transferring now... ---\n" sshpass -p "$server2pswd" scp -r /etc/var/html/www/ server2user@server2ip:$server2path 

i prefer program things in python. below have sample of 1 script use deploy hadoop cluster. can expanded adding more files, commands, or ips.

note being able print going executed before run it. done debug variable.

also note, can accomplished in bash, since not accomplished bash programmer, python easier , less error prone me.

debug=1 import subprocess call = subprocess.call ips = [] in range(0,10):     ips.append("10.0.0.%d"%(i)) commands = 'ls; echo "hello"' def hadoop_setup(ip):         sshtemplate = "ssh hdfs@%s '%s;'"         eachcommand in commands.split(";"):                 sshcall = sshtemplate%(ip, eachcommand)                 if debug: print sshcall                 else: call(sshcall, shell=true)   copyfiletemplate = 'scp %s hdfs@%s:/home/hdfs' file in ['.bashrc']:     ip in ips:         copyfilecall = copyfiletemplate%(file,ip)         call(copyfilecall, shell=true) 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -