Re: distributing files with bash



On 2007-05-09, osiris@xxxxxxxxxx wrote:
I wrote this bash script in order to distribute my .bashrc
and .bash_profile to other hosts that I regularly use
but it doesn't seem to work. One problem is that
somehow "${#HOSTS}" which should contain the number of
elements in the array entitled HOSTS takes a value of 17
for some odd reason. It also doesn't copy the files
even though it seems to execute them when I run the script
with:

bash -x myscript


HOSTS=( isis@xxxxxxxxxxxx horus@xxxxxxxxxxxx aha@xxxxxxxxxxxx )
I=0
while [ "$I" -le "${#HOSTS}" ] ; do
echo "scp of .bashrc and .bash_profile to ${HOSTS[$I]}"
scp ~/.bashrc ${HOSTS[$I]}
scp ~/.bash_profile ${HOSTS[$I]}
I=$(( $I + 1 ))
done

You are missing a colon after the hostname.

And you don't need two calls to scp for each host:

for host in "${HOSTS[@]}"
do
echo "scp of .bashrc and .bash_profile to $host"
scp ~/.bashrc ~/.bash_profile "$host:"
done


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.



Relevant Pages

  • Re: Its time for those 2048-, 3072-, and 4096-bit keys?
    ... you _CAN_ copy between two remote hosts. ... > scp man page says in the second paragraph of DESCRIPTION: ... Here's what I worry about. ...
    (FreeBSD-Security)
  • Re: Fw: Net::SCP::Expect
    ... I am using a proper hostname, and have even tried several different hosts. ... login, hostname, filename, password, etc by scp the file manually. ...
    (perl.beginners)
  • Re: scp: What would cause it to do a local cp instead of my intended scp?
    ... It seems odd to me but maybe that is the only way scp ... FB> can determine the difference between a local and remote copy. ... scp copies files between hosts on a network. ... and uses the same authentication and provides the same security ...
    (comp.security.ssh)
  • scp between two remote machines
    ... Scp copies files between hosts on a network. ... and uses the same authentication and provides the same security as ssh. ... the second host. ...
    (comp.security.ssh)
  • Re: scp between two remote machines
    ... > Scp copies files between hosts on a network. ... > and uses the same authentication and provides the same security as ssh. ... I've seen some implementations of scp attempt to optimize the network ...
    (comp.security.ssh)