Link to home
Start Free TrialLog in
Avatar of John Sheehy
John SheehyFlag for United States of America

asked on

SCP a file to multiple machines using a script

So I have one file that I need to scp to multiple machines.  In the beginning this was easy as we only had 3 machines, now we have over 40 and it gets old real fast typing in the same thing over and over and the host names change all the time.  Once the file is SCP a seperate command runs to execute a script on the host machine.  That part works great.  It SSH ins executes the script and moves onto the next machine.  But I can't seem to get the file to scp using the same methodology as I did with SSH.  What am I doing wrong?

So I did try this but it doesn't seem to work:

sudo=/usr/bin/sudo
ssh=/usr/bin/ssh
scp=/usr/bin/scp

USERNAME = <username>
SCRIPT="<script>"
HOSTS="HOST1 HOST2 HOST3......HOTS40"
VPATH="/h/USERS/local/<username>"

for HOSTNAME in ${HOSTS}; do
       scp *.tar ${USERNAME} ${HOSTNAME} ${VPATH}
done

for HOSTNAME in ${HOSTS}; do
      ssh -l ${USERNAME} ${HOSTNAME} "sudo ${script}"
done

Thank
John
ASKER CERTIFIED SOLUTION
Avatar of Phil Phillips
Phil Phillips
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John Sheehy

ASKER

I am going to try it out here in a minute Will write back within the hour.

Thanks
John
I made the changes and it worked out great.  I am closing this question but I have three more I will be asking.

Thanks
John
Answer was correct and direct to the point.  Very easy to understand.