3

Can anybody let me know how we can copy a file from one server to another in a cron. I know about scp but how we use it in a cron, since we need to pass the password.

Edited

I found this link Expect script that enters a username and password

Can anybody help me to do like this. I'm extremely new to Ubuntu,

Pramod
  • 251

1 Answers1

2

You have two main options:

  1. The bad one: use something like pscp which allows you to send the password. From man pscp:

      -pw password
          Set  remote password to password. CAUTION: this will likely make
          the password visible to other users of the  local  machine  (via
          commands such as `w').
    

    This will require you to have the password in the crontab file, which is a simple text file and that is not a good idea. On my Debian, with pscp 0.63, the password is actually masked in the output of w and ps &co but based on the man page quoted above, you cannot assume that will always be the case.

  2. The better one: setup passwordless ssh for the user who needs to run the scp command. If you don't want to do that for your regular user, just create a new user and run the crontab as that user.

Alternatively, you can set it up the other way around. Instead of having a user on machineA copying a file from machineB, have a user on machineB copy the file to machineA instead.

Yes, you can do this with an expect script but the same security issues will apply if you want to include the password in the script.

terdon
  • 104,119