-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Thu, 27 Sep 2001, Kasper (Swebase) wrote:

>
> Is there any solution to crontab an scp.
>
> So the copying is done automaticly with autologin and so on.
> I want to make a crontab thats copying files every night.

Yes - one way to do this is to use the ssh-agent to store your
keys for a client program to make use of.  This technique is described in the
O'Reilly book "SSH The Secure Shell - The Definitive Guide".

I am assuming that you want to run the client as a non-privileged user.
The first thing you ned to do is start the ssh-agent. Create a  script
to kill any running agents owned by you and start a fresh one:


  #!/bin/sh
  for i in `ps aux | grep $USER | grep ssh-agent | awk '{ print $2 }'`
  do
    kill -9 $i
  done
  ssh-agent  | head -2 > ~/ssh-agent.dat
  chmod 700 ~/ssh-agent.dat
  . ~/ssh-agent.dat

This will start an agent, and create output defining two environment variables,
SSH2_AUTH_SOCK and SSH2_AGENT_PID. These variables are required to enable
clients to find the agent and it's socket.  The output of the ssh-agent command
is in a form which can be saved to a file and run as a script.  By running the
script, the two environment variables are set and exported.  Do a "man ssh-agent"
for details.

  (If you want, you can do this in a login script such as .bash_profile.
   Just make sure the script only runs once, when you login & not
   during startup of an X session.)

Then, you need to add your keys to the agent.  Do this from the command
line with the ssh-add command.  You will be prompted for your passphrase,
which will be stored until you kill the agent or reboot. You can use your
personal key, or add a special key just for the backup, since the
ssh-agent can hold more than one identity.

Now you can create a cron task for yourself, which runs the scp command from
another script:

  #!/bin/sh
  . ~/ssh-agent.dat
  . ~/scp -q -o 'Batch_Mode yes' <source-file> <remote_host>:/<target>

This works for me, YMMV.  I'm sure that there are other ways, too.

Also, be very careful about permissions on script files.


Matt

-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.8
Comment: Made with pgp4pine 1.75-6

iQA/AwUBO7Pvk/cKMP4JTPUAEQL1QwCfScgSrQ+jGTwL9HElMR1BQ1P0xTgAoIIb
qVRvSqZhGHJCg6gL5fo2R+YJ
=ahni
-----END PGP SIGNATURE-----



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to