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.
`awk '{print "ssh -q " $1 " \"echo && hostname && df -h | grep /usr\";"}' essentials`

It is supposed to connect to bunch of hostnames from the file "essentials" and echo their disk space usage. If I get rid of the back ticks you can see what is being executed:

ssh -q hostname1 "echo && hostname && df -h | grep /usr";
ssh -q hostname2 "echo && hostname && df -h | grep /usr";
ssh -q hostname3 "echo && hostname && df -h | grep /usr";

Actual output:

-bash-3.2$ `awk '{print "ssh -q " $1 " \"echo && hostname && df -h | grep /usr\";"}' essentials`
bash: echo && hostname && df -h | grep /usr: No such file or directory

hostname2
/dev/xvda3             23G   13G  9.2G  59% /usr

hostname3
/dev/xvda3             23G  1.5G   21G   7% /usr

Any ideas why that first command doesn't work?

share|improve this question
    
What's the essentials contents? –  BloodPhilia Aug 24 '10 at 23:49
    
Essentials contains host names...1 per line. –  Nick Aug 25 '10 at 0:19

2 Answers 2

up vote 3 down vote accepted

That's because echo && hostname && df -h | grep /usr is treated as a single command, use this instead:

`awk '{print "ssh -q " $1 " bash -c \"echo && hostname && df -h | grep /usr\";"}' essentials`
share|improve this answer
    
That did the trick. Thanks –  Nick Aug 25 '10 at 0:21
xargs --arg-file essentials -I {} ssh -q \{\} bash -c "echo && hostname && df -h | grep /usr"
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.