Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×
User Journal

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 > /proc/sys/vm/drop_caches\""

This discussion has been archived. No new comments can be posted.

Running commands on many remote hosts using ssh and xargs

Comments Filter:
  • Didn't show up in the Preview, but the

    â" should be dashes: -

    • by Qzukk ( 229616 )

      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.

      • by rwa2 ( 4391 ) *

        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

So you think that money is the root of all evil. Have you ever asked what is the root of money? -- Ayn Rand

Working...