Journal rwa2's Journal: Running commands on many remote hosts using ssh and xargs 3
There are a few different ways to run commands on groups or clusters of remote nodes, depending upon how complex the command.
Assuming your machines are named "node01" - "node10" :
# Run a command in parallel on all remote nodes
# results come back in random order as they are received.
pdsh â"w "node[01-22]" df
# pdsh allows some more complex listings of hosts
pdsh â"w "node04,node[06-09]" reboot
# Run a command sequentially on all remote nodes
# slow, but results come back in order
seq â"w 1 22 | xargs â"I '{}' ssh node'{}' df
# Run a command in parallel on all remote nodes without pdsh
seq â"w 1 22 | xargs â"P 22 â"I '{}' ssh node'{}' df
# Run a command in parallel needing pipes on the remote host
# Otherwise, pipes are processed locally
seq â"w 1 22 | xargs â"P 22 â"I '{}' ssh node'{}' \
"ps afx > \`hostname\`.txt"
# Run a command in parallel needing root
# sudo requires a tty, hence we pop up xterm windows
seq â"w 1 22 | xargs â"P 22 â"I '{}' xterm â"e \
"ssh -t node'{}' sudo gdm-restart"
# Run a command in parallel needing root and pipes on the remote host
seq â"w 1 22 | xargs â"P 22 â"I '{}' xterm â"e \
"ssh -t node'{}' sudo bash â"c \"echo 3 >
argh formatting (Score:2)
Didn't show up in the Preview, but the
â" should be dashes: -
Re: (Score:2)
Welcome to unicode. Or slashdot's lack of it.
Personally, I'd fix wherever you pasted that stuff from, since people trying to copy and paste from there into a unicode-capable terminal will get things that look like minus signs but the command won't see them as minus signs, and will be really confused when the command doesn't run.
Re: (Score:2)
lol
The original doc was from MS Word for the benefit of my cow-orkers, which itself took /way/ too much fixing... Even after disabling all the annoying autocorrect options and "replace quotes with smart(?!) quotes," it still insisted on doing ' as backticks
If you have any recommendations on a good techie blog platform that can deal well with code snippets, let me know ;) But so far, /. seems to have more "community" interaction and actually seems less annoying than the other geeking/coding boards I've se