Bash Loop
I consider myself a very basic Bash Scripting kind of guy. I like it, it feels a lot like basic, and I’m sure I’ll get better at it. Today, I was playing with a for-next loop.
I have several servers I’m in charge of, and I have ssh set up so I don’t have to type a password when I want to connect to them. So at the prompt, I can type this:
[code]
$ for i in server1 server2 server3
> do ssh $i uname -a
> done
[/code]
and the computer will connect to the servers in sequence and run the uname -a command (which tells some specific things about the linux kernel).
This is useful because I am trying to make these different servers all the same. And I can run programs with the version flag ( mysql -v ) and figure out which ones need to be upgraded. Or if I got better at this, I could use awk and sed to modify the hosts file, or an initialization script, or whatever. It’s true that I could use some other tool (like cssh; cluster ssh ), but this would be a primitive way to manage it

on November 1st, 2005 at 1:44 pm
[...] One thing to be aware of when doing this bash loop; the ssh that runs within the loop won’t have the full environment variable set for the user on the remote computer. So if you have two versions of php, you may be checking the version of the wrong one. [...]