Link to home
Start Free TrialLog in
Avatar of Dhalgren
Dhalgren

asked on

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?
Avatar of yowkee
yowkee

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?
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.

ASKER CERTIFIED SOLUTION
Avatar of bcwhite
bcwhite

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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:
https://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.

https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
https://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange