autodownload via rcp/scp

I need to write a script for the crontab which will download a file from our remote server. Read man pages on scp and wrote;

scp ~/remotefiles/tst.txt sys@server2.com:~/remotefiles/tst.txt

OK, this works but it asks for password- so I can't use it as an automated crontab script. Man pages say scp asks for passwd, rcp doesn't. But, I have same problem with rcp. I checked to make sure I have /etc/hosts.equiv and /usr/home/sys/.rhosts. This is running on a virtual server.

So, how do I write a script that can either answer the password question, or wirte the rcp command so that it doesn't ask in the first place?
DhalgrenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yowkeeCommented:
suppose you set the rhosts correctly, the rcp syntax would be like:

rcp sys@server2.com:~/remotefiles/tst.txt ~/remotefiles/tst.txt; which copy tst.txt from server2.com to localhost.
What's the error when you do the rcp?
0
bedotCommented:
are you sure your .rhosts is in the HOME directory of the user doing the rcp ?
generally there is only one file .rhosts containing all declarations, and then linked in each homme directory of each login used for rcp.

0
bcwhiteCommented:
Use scp...

First, generate a non-password private/public key set.  Use "ssh-keygen" but just hit <return> when prompted for a password.

  ssh-keygen -b 1024 -f identity-nopw -C "no-password copies"

Add the generated public key to the ".ssh/authorized_keys" on the remote system.

Then, change your scp command to include the "-i" option...

  scp -i ~/.ssh/identity-nopw ~/remotefiles/tst.txt sys@server2.....

WARNING:  This is a security hole since anybody that can read the "identity-nopw" file (someone with your password or at an unattended console) will have remote access to the other machine.  Standard keys are password protected, but you've specifically said "no password" for this one.  There may be ways in ssh to reduce access on a per-key basis.  You'll have to look in to that if security is a concern.

One last note...  If you have problems with this, check the configuration of the ssh server.  There is an option to disallow non-password-protected key access.

-- Brian
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
juipinhsuCommented:
I don't know if 'expect' works with cronjobs...
but try this:

1.  autoexpect scp ~/remotefiles/tst.txt sys@server2.com:~/remotefiles/tst.txt

     Doing everything like usual pretending that you are typing scp ~/remotefiles/tst.txt sys@server2.com:~/remotefiles/tst.txt  by hand.


2.  Step 1 will generate an expect script named script.exp

3. rename script.exp to whatever name you like.

4.  Now put that script into crontab.
    Some system may not be able to execute expect as cronjob by recognized the '#!/usr/bin/expect' line.  In that case, you have to put a /usr/bin/expect before your script when adding a crontab entry.
 (NOTE: your expect may reside in other directory than /usr/bin/  modify the path accordingly)

CAUTION:  The automatic generated script contains plain password.  You had better set proper reading (and other) permissions for that script file.  Also avoid from letting others using your account.
0
MoondancerCommented:
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  Or if you are an EE Pro user, click the link below to select open items for your Member ID using Power Search:
http://www.experts-exchange.com/jsp/qPowerSearch.jsp.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.