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

I'm new to this, wondering if someone could help.

I need to ssh to a server and bind commands to it, which copies a directory, zips it up etc..

ssh user@123.45.67.89 ; cd /to/directory/ ; zip these files

Something similar to the above. If anyone could offer advice, would be a great help! Thanks

share|improve this question

1 Answer 1

You can append a command to ssh:

ssh user@123.45.67.89 "cd /to/directory/ ; gzip -r somedir > test.zip"

Be careful of string expansion:

Double quotes get expanded on the local machine.

ssh user@123.45.67.89 "gzip -r /var/www/$(hostname)/httpdocs > test.zip"

expands to: gzip -r /var/www/localhostname/httpdocs > test.zip

Single quotes get expanded on the remote machine.

ssh user@123.45.67.89 'gzip -r /var/www/$(hostname)/httpdocs > test.zip'

expands to: gzip -r /var/www/remotehostname/httpdocs > test.zip

share|improve this answer
    
Am I missing something, or did you re-draft the expansion examples and break them in the process? –  James Green Mar 3 '11 at 13:08
    
@Jimbo nope, the examples above are correct, what's broken for you? –  Andy Mar 3 '11 at 15:55
    
I don't see where the 'rm' or the '-rf' come from –  James Green Mar 4 '11 at 9:41
    
@Jimbo Aha point taken, thanks! –  Andy Mar 4 '11 at 10:32
    
ah that's alright, I was beginning to doubt my sanity! –  James Green Mar 5 '11 at 0:34

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.