Ssh – How to return multiline from remote SSH command

remotessh

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

Best Answer

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
Related Topic