Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Linux, you can use xargs -d, to quickly run the hostname command against four different servers with sequential names as follows:

echo -n 1,2,3,4 |xargs -d, -I{} ssh root@www{}.example.com hostname

It looks like the OSX xargs command does not support the delimiter parameter. Can you achieve the same result with a differently formatted echo, or through some other command-line utility?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

How about:

echo {1..4} | xargs -n1 -I{} ssh root@www{}.example.com hostname

From man xargs:

-n number
Set the maximum number of arguments taken from standard input for each invocation of utility.
share|improve this answer
    
If the values can contain spaces, linefeeds, or tabs, you could use something like printf 'a\0a' | xargs -0 -n1 echo. –  ؘؘؘ Oct 18 '12 at 7:20

Alternatively, you can always install GNU xargs through Homebrew and the GNU findutils package.

Install Homebrew:

ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)

Follow the instructions. Then install findutils:

brew install findutils

This will give you GNU xargs as gxargs, and you can use the syntax you're accustomed to from GNU/Linux. The same goes for other basic commands found in the findutils package such as gfind or glocate or gupdatedb, which have different BSD counterparts on OS X.

share|improve this answer

If you want it run in parallel, use GNU Parallel:

parallel ssh root@www{}.example.com hostname ::: {1..4}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.