The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]

Article Feedback - scp tricks
 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Previous Message  |  Next Message 
 ssh tricks
Author: James Flemer 
Date:   08-03-03 03:52

First off, anyone who uses ssh or scp with lots of different hosts should take the time to read the ssh_config(5) man page. It is very useful if you have accounts with different usernames, see the 'User' parameter.

Ok, now, since this article was about scp, let me talk about some nice things you can do with ssh. You all know that copying a whole directory tree sometimes causes problems, and that is why it is common to use tar to ensure permissions, ownership and symlinks are handled correctly. The example in tar(1) is:

tar -cf - -C srcdir . | tar xpf - -C destdir

Now, consider this when the destination is a remote host. Ssh can be used to make this very simple, just say:

tar -cf - -C srcdir . | ssh remote_host tar xpf - -C destdir

where 'srcdir' is on the local host, and destdir is on the remote.
Similarly, to copy from a remote host:

ssh remote_host tar -cf -C srcdir . | tar xpf - -C destdir

Another way I use ssh is to redirect output of a command on one host to a file on another host. For example, if I was compiling something and for some reason wanted the make log on another computer, I would run (using a Bourne shell):

make buildworld 2>&1 | ssh remote_host cat \> /tmp/make.log

The output of buildworld is sent over ssh to the cat process on the remote host, which just writes it to it's stdout. In this case it's stdout is redirected to /tmp/make.log. Make sure you escape the redirect (>) on the command line so it is evaluated by the remote not the local host.

Have fun.
-James

 Reply To This Message  |  Forum List  |  Flat View   Newer Topic  |  Older Topic 

 Topics Author  Date
 ssh tricks   new
James Flemer 08-03-03 03:52 
 Re: ssh tricks   new
James Flemer 08-03-03 03:55 
 Re: ssh tricks   new
pierre-yves verdon 08-03-03 11:00 
 Re: ssh tricks   new
Andy Harrison 13-03-03 21:25 
 Re: ssh tricks   new
Ben 14-03-03 10:40 
 Re: ssh tricks   new
frank 24-03-04 23:30 
 Re: ssh tricks   new
Dan 24-03-04 23:53 


 Forum List  |  Need a Login? Register Here 
 User Login
 User Name:
 Password:
 Remember my login:
   
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.
How to get the most out of the forum

phorum.org