Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a script that backs-up remote systems, and want it to display disk space on the remote backup device prior and post running backup script.

Thanks to another post have learnt how to run remote commands via SSH such as (SSH keys have been setup for auto login).

echo `ssh -t user@host uname -a`

However, how can I get a multi line response that comes from a command such as

echo `ssh -t user@host df`

Response just shows the last line of output from df

share|improve this question
mattias is right; this is useless use of echo (and backticks, besides). :) if you post your whole script, we can probably advise on a better way to do it. (hint: store command output in variables to display later) – darkuncle Jan 7 '12 at 0:13
up vote 5 down vote accepted

That sounds overly complicated way to SSH somewhere and call a command.
Just type:

ssh user@host df

Voila. :)

Edit 1
Example of remote output parsing:

ssh user@host df -P | tail -n +2 | awk '{print $6 "," $4}'

Outputs comma separated list of mountpoint,availablespace like:

share|improve this answer
Sorry. I should have noted that command is to go into a script that runs backups and currently shows disk space on local host prior and post backup. However I also want to display disk space on the remote backup device prior and post running backup script. – Eureka Ikara Jan 7 '12 at 0:10
Well, its still the same basically. You can just put it inside a script, parse the output like from any other command, etc. So this is still the right thing to do. :) – Mattias Ahnberg Jan 7 '12 at 0:31
You are right. I have adapted your suggestion using grep to get exactly what I needed. – Eureka Ikara Jan 7 '12 at 1:33
Eureka, forgive me for pointing out that local etiquette is that, when you're happy with an answer to your question, you accept it by clicking on the tick outline next to it. That drives SF's repuatation engine, both for you and for Mattias. You might want to go back and review your previous questions to see about the answers for those, too, because at the moment we see a red warning next to your name that says "0% accept rate" - and that may discourage people from answering your questions in future. Sorry if you know all this! – MadHatter Jan 7 '12 at 9:18
Thank you, @MadHatter. :) – Mattias Ahnberg Jan 7 '12 at 12:23

This may not be the most efficient or elegant way, but how about something like:

REMOTEDF="ssh username@hostname df"

echo "Pre-backup df from hostname"
echo date >> $HOME/df-backups.out
echo "" >> $HOME/df-backups.out
$REMOTEDF >> $HOME/df-backups.out
echo "" >> $HOME/df-backups.out

--perform your backup--

echo "Backup of hostname is complete; post-backup df:"
echo date >>
echo "" >> $HOME/df-backups.out
$REMOTEDF >> $HOME/df-backups.out
echo "" >> $HOME/df-backups.out

share|improve this answer
Thank you all for suggestions. I have been able to adapt the remote output parsing command from Mattias to do exactly what I need. – Eureka Ikara Jan 7 '12 at 1:31

here echo is the source of trouble. Remove the echo and you will get mutiline output. Why not just do ssh username@hostname cmd Why -t ?

share|improve this answer

Your Answer


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.