0
ssh $remote '( df -k )' > $REMOTE_SPACE
for (( i=0; i<no_dest; i++ ))
    do
        ssh $remote "( aux_free_space[i]=$( du -sk ${aux_dest[${i}]}  | cut -f 1 ) )"
    done

All work ok apart from populating the array aux_free_space[]; i think the du runs on the local host.

  • ssh $remote works fine
  • aux_free_space is initialised at the beginning
  • aux_dest is already populated
2
  • also tried: ssh $remote '( aux_free_space[i]=$( du -sk ${aux_mount[${i}]} | cut -f 1 ) )' Commented Nov 19, 2014 at 14:33
  • and ssh $remote ' aux_free_space[i]=$( du -sk ${aux_mount[${i}]} | cut -f 1 ) ' Commented Nov 19, 2014 at 14:33

1 Answer 1

2
ssh $remote df -k > $REMOTE_SPACE

for ((i = 0; i < no_dest; i++)); do
    aux_free_space[i]=$(ssh $remote du -sk ${aux_dest[i]} | cut -f 1)
done

The array assignment has to be pulled out into the local shell, but the du must be done remotely. The cut can be done on either side, so to cut down on the levels of quoting you can do it locally. (If du returned a lot of output you might choose to do the cut remotely to cut down on network traffic.)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the explanation. Will keep it in mind. From what I understand in this case the cut is done remotely. If it were to be done locally would it be?: aux_free_space[i]=$(ssh $remote du -sk ${aux_dest[i]}) | cut -f 1
As I wrote it the cut is local. To do it remotely, write aux_free_space[i]=$(ssh $remote "du -sk ${aux_dest[i]} | cut -f 1").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.