[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

autodownload via rcp/scp

Posted on 1999-11-12
5
Medium Priority
?
564 Views
Last Modified: 2013-12-26
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?
0
Comment
Question by:Dhalgren
5 Comments
 
LVL 4

Expert Comment

by:yowkee
ID: 2204739
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
 
LVL 2

Expert Comment

by:bedot
ID: 2207970
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
 
LVL 1

Accepted Solution

by:
bcwhite earned 200 total points
ID: 2211639
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
 
LVL 1

Expert Comment

by:juipinhsu
ID: 2215179
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
 
LVL 1

Expert Comment

by:Moondancer
ID: 6826274
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

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question