4 ms·
Yeah, before I was heavily into automation (i.e. puppet) this was my go to command. Use a for loop and ssh to run things on a group of systems. for host in h
by WestCoastJustin 13y ago
Yeah, before I was heavily into automation (i.e. puppet) this was my go to command. Use a for loop and ssh to run things on a group of systems.
for host in h-abc h-def h-ghi h-jkl h-mno h-pqr h-stu h-vwx h-yza;
do
ssh -l root $host "hostname; echo "1.1.1.1 server" >> /etc/hosts";
done
This would iterate over hosts (h-abc .. h-yza) and run the commands "hostname; echo "1.1.1.1 server" >> /etc/hosts". Or maybe use a for loop and scp to push the files out and then run md5 to verify they are correct. It was a hack but useful for a small set of machines.
ps. if you are interested in learning about puppet, I have put together a screencast about it @ http://sysadmincasts.com/episodes/8-learning-puppet-with-vagrant http://sysadmincasts.com/episodes/8-learning-puppet-with-vag...
- philsnow 13y agomake a small change: for host in ... ; do ssh -l root $host "..." & done; wait and it's very parallel. All that key exchange takes a while, so it's not ridiculously fast, but it's pretty good. If you've got ControlMaster set up already to be per-host, this might very well be very fast the second time.
- revscat 13y agoYou may want to look into using GNU parallel with that.
- derekp7 13y agoAlso check out xargs with the -P 10 -n 1 flags (for example) -- to limit at most 10 parallel tasks running at the same time. Useful if you don't have GNU parallel installed where you happen to be working (everyone has xargs installed).
- dredmorbius 13y agodsh (distributed/dancer's shell) is a wrapper around ssh which provides that capability. Plus you can define hostlists.