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,

  • you need a script – nux Apr 21 '14 at 11:04
  • yes, i know how to copy from one server to another through terminal, but i don't how to write it in cron, since it will ask the password. – Pramod Apr 21 '14 at 11:06
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.

  • thanks, i will try this, sorry im not able to give upvote. – Pramod Apr 21 '14 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.