Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to run

something > file

on a remote system through ssh, but if I run

ssh host something > file

the redirection is executed locally as ssh etc > file

I've tried it with ' or '' or dd or with a pipe | instead, but I can't get it to work. How can this be done?

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

Try:

ssh host 'sh -c something > file'
share|improve this answer
    
thanx -- it works! –  franziskus Sep 5 '10 at 15:17
2  
Since ssh passes that part of its command line to the shell anyway, you don't need the sh -c part. –  Jander Jan 22 '11 at 5:04
add comment

Even simpler, instead of:

ssh host something > file

do:

ssh host "something > file"
share|improve this answer
add comment

The suggested solution works with pipes as well

ssh host 'some_command | some_other_command'
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.