Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

3 Answers

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:

/,1393276
/usr,3524132
/var,2560004
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
1  
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
show 2 more comments

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 >>
$HOME/df-backups.out
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
add comment

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
add comment

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.