help on scp script (309 Views)
Reply
Super Advisor
NDO
Posts: 535
Registered: ‎12-10-2003
Message 1 of 10 (309 Views)

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

Please use plain text.
Honored Contributor
Patrick Wallek
Posts: 13,758
Registered: ‎06-21-2000
Message 2 of 10 (293 Views)

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.

Please use plain text.
Super Advisor
NDO
Posts: 535
Registered: ‎12-10-2003
Message 3 of 10 (290 Views)

Re: help on scp script

Thank you, that's the only thing needed right?
Please use plain text.
Honored Contributor
Patrick Wallek
Posts: 13,758
Registered: ‎06-21-2000
Message 4 of 10 (287 Views)

Re: help on scp script

[ Edited ]

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.

Please use plain text.
Super Advisor
NDO
Posts: 535
Registered: ‎12-10-2003
Message 5 of 10 (278 Views)

Re: help on scp script

yes, its root
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 25,004
Registered: ‎03-06-2006
Message 6 of 10 (271 Views)

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.

Please use plain text.
Super Advisor
NDO
Posts: 535
Registered: ‎12-10-2003
Message 7 of 10 (257 Views)

Re: help on scp script

just 84 files
Please use plain text.
Super Advisor
NDO
Posts: 535
Registered: ‎12-10-2003
Message 8 of 10 (257 Views)

Re: help on scp script

but in this case do I have also to setup connections without passwords?
Please use plain text.
Honored Contributor
Patrick Wallek
Posts: 13,758
Registered: ‎06-21-2000
Message 9 of 10 (250 Views)

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.

 

 

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 25,004
Registered: ‎03-06-2006
Message 10 of 10 (245 Views)

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.  :-)

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation