[Linux-disciples] Shell Scripting
Stephen R Laniel
steve at laniels.org
Tue Dec 7 00:13:24 EST 2004
On Mon, Dec 06, 2004 at 09:46:31PM -0500, Jason Smith wrote:
> I have been using rsync to transfer files back and forth from my laptop
> at home (powerbook) and my server at work. I want to automate this
> task. I am assuming that a shell script is the simplest approach.
>
> Any thoughts on:
>
> 1. Is a shell script the best solution?
I'm not sure that it is. You're doing it over ssh, I assume,
so the real bugger of the whole process -- shell scripted or
not -- will be the passphrase. Rsync has --include and
--exclude options (see the man page, plus the documentation
in /usr/share/doc/rsync), so if you're consistently copying
the same files you could do it all with one command -- no
real 'scripting' (in the sense of complicated pipes or
logic) required.
Let's call your local machine Local and the remote machine
(the one you're copying to) Remote. Assume your username on
Local is 'localuser', and on remote is 'remoteuser'. Then
you'll need to do the following:
1) Generate an ssh public key for yourself on Local:
ssh-keygen -t dsa
Take the default answers to all questions (should be able to
press enter through them all). This will generate a file:
~localuser/.ssh/id_dsa.pub . This is your ssh public key.
2) Copy .ssh/id_dsa.pub to the remote machine:
scp ~localuser/.ssh/id_dsa.pub remoteuser at Remote:
This will drop id_dsa.pub in ~remoteuser/id_dsa.pub . (Note
that the ':' at the end of that last command is supposed to
be there.)
3) ssh to the remote machine:
ssh remoteuser at Remote
4) Append the contents of id_dsa.pub to
~remoteuser/.ssh/authorized_keys ; if that file doesn't
already exist, create it:
cat ~remoteuser/id_dsa.pub >> ~remoteuser/.ssh/authorized_keys
5) (Purely optional.) Delete the now-extraneous file on
Remote:
rm ~remoteuser/id_dsa.pub
6) Disconnect from Remote:
exit
Now every time you run rsync connecting from Local to Remote
(but not from Remote to Local -- for that, you'll need to
run steps 1) through 6) with Local, Remote, localuser and
remoteuser swapped appropriately), you can get through
without a passphrase. That should simplify your problem
quite a bit.
--
``A mysterious voice on the sound track advises David to
escape. He is supplied with a bar of soap, half a loaf
of bread, a compass, and an envelope not to be opened
until he gets to Denmark or finds Carmen Sandiego,
whichever comes first. Sorry about that.''
-Roger Ebert, http://shorl.com/dykipydrasana
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20041207/81f8b009/attachment.pgp
More information about the Linux-disciples
mailing list