LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-25-2016, 07:41 AM   #1
rsi142
LQ Newbie
 
Registered: Oct 2016
Posts: 9

Rep: Reputation: Disabled
SCP copying error


Hi folks,
I want to copy the file from remote server to my system for that i had written the shell script
scp user@ip source destination
it is working fine

but now i had to copy the file from two different file locations in the remote machine

for that i had written the two times
scp user@ip source destination
scp user@ip source1 destination1

but what is happening that it is creating the file not copying the content of the file

it is just copying the content of the first file itself only
 
Old 10-25-2016, 08:14 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,836
Blog Entries: 13

Rep: Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893
Hi and welcome to LQ.

That second file might be not synced to the file system and so information for the file might be unavailable for the copy operation.

I believe that SCP would give you an error if the file did not exist for copying.

If possible, could you post an example of this problem?
 
Old 10-25-2016, 09:33 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,084
Blog Entries: 3

Rep: Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665
Quote:
Originally Posted by rsi142 View Post
for that i had written the two times
scp user@ip source destination
scp user@ip source1 destination1
Welcome. "scp" needs to have the user and hostname associated with the path+file name to know which machine to copy to or from. So what you probably mean is either this to copy from remote to local:

Code:
scp user@ip:/remote/path/to/source /local/path/to/destination
scp user@ip:/remote/path/to/source1 /local/path/to/destination1
or this to copy from local to remote:

Code:
scp /local/path/to/destination user@ip:/remote/path/to/source 
scp /local/path/to/destination1 user@ip:/remote/path/to/source1
"scp" is good if you want to copy the whole file each and every time. If you have a file that updates but otherwise stays the same, then "rsync" over SSH is a better choice.

Check the manual page for "scp" for the details.

Code:
man scp
 
Old 10-25-2016, 10:40 AM   #4
rsi142
LQ Newbie
 
Registered: Oct 2016
Posts: 9

Original Poster
Rep: Reputation: Disabled
scp error

Thanks for the reply
actually i had created a shell script in i had used
spawn scp copying command

in that i had to copy two files from two different folders so i had written two time scp command for copying the files what is happening that first file it is copying but in case of second file one file is created but it is empty file no conent is present in it.


If required tell i will share the the file to
 
Old 10-25-2016, 10:48 AM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,836
Blog Entries: 13

Rep: Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893
As I always say, you can add "set -xv" to your script to enable verbose debugging for the script. You should run it from a terminal/command line (those are just different terms to describe the same thing, sorry many people question what the meaning of those are sometimes, you likely know this already, no offense intended). Within the command line you'll see the verbose output of each action for your script, plus you'll see any errors generated.

Please make sure that the second file exists on the system it is being copied from and that the file has content in it. I think you have indicated that you feel this is true. I'd recommend you try this with yet a third file. Please also verify that the second file is not a directory, there is a -r flag to use with scp to recurse into directories. Perhaps also this is permissions. Does the scp user have permissions to read files from that other directory?
 
Old 10-25-2016, 10:56 AM   #6
rsi142
LQ Newbie
 
Registered: Oct 2016
Posts: 9

Original Poster
Rep: Reputation: Disabled
yes file exist on the other server if file doest not exist then it would give the error that file does not exist
 
Old 10-25-2016, 02:22 PM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,084
Blog Entries: 3

Rep: Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665
Can you post your exact script, minus any sensitive parts? From what you first posted above, the syntax you are trying to use for "scp" is not quite right and it would be helpful to see exactly what you have.
 
Old 10-26-2016, 02:29 AM   #8
rsi142
LQ Newbie
 
Registered: Oct 2016
Posts: 9

Original Poster
Rep: Reputation: Disabled
Scp error

spawn scp root@10.207.16.45:/u02/opt/logs/mk_prod.out .
expect "*root@10.20.1.5's password:" {
send "password\r"
expect "\r"
expect "*\r"
}

spawn scp root@100.20.1.5:/u02/opt/weblogic/do...ogs/access.log .

expect "*root@100.20.1.5's password:" {
send "password\r"
expect "\r"
expect "*\r"
}

here i am trying to automate the process of copying so using expect and send command for it
mk_prod.out is getting copied but not access.log
for checking purpose i had also verified it by placing acess.log at first at that time access.log is also getting copied

only the file which at the top is getting copied only
 
Old 10-26-2016, 02:38 AM   #9
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,084
Blog Entries: 3

Rep: Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665
Quote:
Originally Posted by rsi142 View Post
only the file which at the top is getting copied only
Ok. By the way, keys are the safer way to do the connecting.

Do both instances of "scp" actually work when you try them manually?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] scp error while copying files between two remote computers austinium Linux - Newbie 7 02-16-2014 10:27 AM
[SOLVED] copying thousands of files via SCP vjramana Linux - Networking 1 09-26-2012 01:06 AM
ssh:-error copying using scp matrix13 Linux - Software 1 07-09-2007 12:01 PM
SCP copying directories between servers astrollama Linux - Software 5 10-13-2006 04:10 AM
scp copying from Linux to windows richard3403 Linux - Networking 2 11-06-2003 08:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration