Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
01-24-2012, 11:55 PM
|
#1
|
|
Member
Registered: Jul 2004
Location: VIC, Australia
Distribution: RHEL, CentOS, Ubuntu Server, Ubuntu
Posts: 350
Rep:
|
Parallelizing Copying public key to authorized_keys file
Here's a script I am using to copy my public key to the ~/.ssh/authorized_key on the 300+ servers I have at work:
Code:
# allservers.txt file contains all servers
# pass.txt file contains user's password
for i in $(cat allservers.txt); do
echo "Trying $i"
ping -c 1 -W 1 $i > /dev/null # to see if server is online
if [ $? -eq 0 ]; then
sshpass -f pass.txt ssh-copy-id $i
if [ $? -eq 0 ]; then
echo "Done $i"
fi
else
echo "ping failed"
fi
echo -e "\n"
done
The problem is that it is trying each of the servers in turn and taking a long time. Any trick to make it parallel so that it does, say, 10 servers at a time?
|
|
|
|
01-25-2012, 01:35 AM
|
#2
|
|
Member
Registered: May 2010
Location: Planet Earth
Distribution: Debian
Posts: 766
Rep: 
|
What if your script split allservers.txt in 2 parts and then work with each half and then split each half and then split all 4 parts so it will be 8 parts and again and again, recursively it could keep spliting until there is nothing to split, at the same time it can pass the keys for each server.
I hope this make sense to you.
Regards
|
|
|
|
01-25-2012, 02:44 AM
|
#3
|
|
Member
Registered: Mar 2010
Distribution: Debian
Posts: 201
Rep:
|
Why bother throttling it?
Code:
# allservers.txt file contains all servers
# pass.txt file contains user's password
for i in $(cat allservers.txt); do
(
echo "Trying $i"
ping -c 1 -W 1 $i > /dev/null # to see if server is online
if [ $? -eq 0 ]; then
sshpass -f pass.txt ssh-copy-id $i
if [ $? -eq 0 ]; then
echo "Done $i"
fi
else
echo "$i ping failed"
fi
echo -e "\n"
) &
done
|
|
|
|
01-25-2012, 11:36 AM
|
#4
|
|
Senior Member
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 1,648
|
Split it into two scripts
script1:
Code:
echo "Trying $1"
ping -c 1 -W 1 $1 > /dev/null # to see if server is online
if [ $? -eq 0 ]; then
sshpass -f pass.txt ssh-copy-id $1
if [ $? -eq 0 ]; then
echo "Done $1"
fi
else
echo "ping failed"
fi
echo -e "\n"
script2:
Code:
for i in $(cat allservers.txt); do
nohup script1 $i &> $i.log &
done
If you don't want all 300 to blast your network at once, you can put a sleep statement and a counter into script2, so it launches say 10, then waits 3 seconds before launching the next 10, and so on.
|
|
|
|
01-25-2012, 01:23 PM
|
#5
|
|
Member
Registered: Mar 2010
Distribution: Debian
Posts: 201
Rep:
|
In suicidaleggroll's factoring you're going to want `&>>` not `&>`, or put the `&>` after the `done`. It's a pretty safe bet you're using bash, but if not, `&>` is a bashism, `1>>logfile 2>>&1` is the portable spelling.
EDIT: Oops, sorry, that script makes 300 logfiles, that'll work. Need. Less. Coffee.
Last edited by jthill; 01-25-2012 at 01:25 PM.
Reason: suicide's factoring does 300 logfiles, I missed that.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 05:09 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|