1752401 Members
5665 Online
108788 Solutions
New Discussion

Re: help on scp script

 
NDO
Super Advisor

help on scp script

Hi

 

I have the following script, that is not working:

 

for files in `ls -lrt | awk '{if ($8 == "2013")print $0}'`
do
/usr/bin/scp -p $files root@10.1.20.31:/fs1/bscsrtx/BSCS_iX/WORK/MP/UDR/RLH/M16S11A4V1A11VRLUCO/ERR/OLD_FILES/
done

 so I am trying to copy all 2013 files to another server, so when I run it:

Password:
1: No such file or directory
Password:

 keeps on asking for password....

9 REPLIES 9
Patrick Wallek
Honored Contributor

Re: help on scp script

You need to set up SSH so that it can log into the remote server without asking for a password.

 

The is done by appropriately setting up public / private key access between the servers.

NDO
Super Advisor

Re: help on scp script

Thank you, that's the only thing needed right?
Patrick Wallek
Honored Contributor

Re: help on scp script

Yes, that should be all that is needed.

 

Just make sure that the user that is running the scp is that one that is allowed to login as root on the remote server.

NDO
Super Advisor

Re: help on scp script

yes, its root
Dennis Handly
Acclaimed Contributor

Re: help on scp script

>I am trying to copy all 2013 files to another server

 

If you don't have zillions of files, you can use this to copy all in one scp command:

files=$(ls -lrt | awk '{if ($8 == "2013") print $9}')

/usr/bin/scp -p $files root@10.1.20.31:/fs1/bscsrtx/BSCS_iX/WORK/MP/UDR/RLH/M16S11A4V1A11VRLUCO/ERR/OLD_FILES/

 

Note: In your original script, you should also be printing $9, the filename and not the whole line.

NDO
Super Advisor

Re: help on scp script

just 84 files
NDO
Super Advisor

Re: help on scp script

but in this case do I have also to setup connections without passwords?
Patrick Wallek
Honored Contributor

Re: help on scp script

The method of passing the list of files to copy to the scp copy command has nothing to do with how scp actually functions.

 

If you want to use SCP to copy the files without having to enter a password, then YES you do need to set up public / private keys to enable passwordless login.

 

 

Dennis Handly
Acclaimed Contributor

Re: help on scp script

>but in this case do I have also to setup connections without passwords?

 

Well, you'll only need to type in the password once, each time you run the script.  :-)