`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?

link|improve this question

50% accept rate
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
feedback

2 Answers

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

Your Answer

 
or
required, but never shown

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