cp not coping properly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cp not coping properly
# 1  
Old 11-19-2008
Question cp not coping properly

Hi,

I'm trying to copy the directories from one location(/tmp/source/) to other(/tmp/dest/).
for this I have written a PERL script.
snippet of code
Code:
$sourcePath = "/tmp/source";
$destPath = "/tmp/dest";
opendir(DIR, $sourcePath );
while($dir = readdir(DIR))
{
	if($dir ne "." && $dir ne "..")
	{
		$sourceDir = $sourcePath . "/" . $dir;
		$destDir = $destPath . "/" . $dir;
		$cpCMD = "cp -rf $sourceDir $destDir";
                system $cpCMD;

	}
}

For Some directories it is working fine.
But for others the directories are created like /tmp/dest/report1/report1/files instead of /tmp/dest/report1/files.Smilie

If I'm not clear, Please revert.

can somebody help me?

Thanks in Advance.

Last edited by prashants; 11-19-2008 at 04:41 AM..
# 2  
Old 11-19-2008
Well the sort of issue you may get with cp is when it sees a link, and copies it ...as a directory with all its content etc...

Why not use cpio? or test if dir is a true dir or a symlink...

why cpio? It will copy depending of your options the links as links... (but there are also other commands to choose from)
how?
source= /tmp/source
dest=/tmp/dest

In HPUX...
Code:
cd $source;
find . -print|cpio -pduml $dest

This is just one solution, Im sure there are plenty of valid ways to do the same...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Coping files that containing 2010

I want to use the find command to copy files that contain 2012 from one directory to another. I tried find /Volumes/movies1 -name "*.2012.*" -exec cp -nRv "{}" /Volumes/pdrive/ \; (2 Replies)
Discussion started by: codecaine
2 Replies

2. Shell Programming and Scripting

Problems coping a file in a shl script

I have the following in a shl script: SCRIPT_PATH="/u01/app/banner/test/skid/plus/"; FILE_PATH="/nfs/mercury/u03/banner/test/skid/log"; LIST_FILE_PATH="/u01/banjobs/TEST"; SCRIPT_NAME="szpcal1.sql"; FILE_NAME='new_applicant_list'; I want to copy the file FILE_NAME to LIST_FILE_PATH ... (10 Replies)
Discussion started by: rechever
10 Replies

3. Shell Programming and Scripting

Progress bar while coping a file needed.

Hi guys I want to create a script which will show the amount of data that is been copied from one location to another location. For example: Say i have a file called abc.img which is approximately 4 gb of size therfore everytime i copy the file from one location to another i want a progress bar... (3 Replies)
Discussion started by: pinga123
3 Replies

4. UNIX for Dummies Questions & Answers

coping files from unix to windows

hey all, i have a unix computer and a windows os computer connected in the same local network i want to copy the etc folder to the windows computer so if my unix computer's hard disk rashes i can restore it from my windows computer. my first problem is i'm kinda lame with unix...i know... (3 Replies)
Discussion started by: shwinky
3 Replies

5. UNIX for Dummies Questions & Answers

Coping Files for a specific date range

Hi, we have file name appended by date in yymmdd format .. ex: abc090101.dat I need to copy all the files between abc090101 to abc090331.. could you plz help me.. Thanks. (1 Reply)
Discussion started by: kolariya4u
1 Replies

6. UNIX for Advanced & Expert Users

mail is not sent, instead just coping into /var/spool/queue dir

Hi, I have some problems w/ the sendmail. I see that messages are queued in the /var/spool/mqueue and they are never sent to the recipients. This problem just suddenly started without any modifications in the current configuration. I already started and stop the sendmail and it did not help.... (3 Replies)
Discussion started by: ktanya
3 Replies

7. UNIX for Dummies Questions & Answers

coping directories?

Is this possible? If so could i have the command for it thanks!! (2 Replies)
Discussion started by: JamieMurry
2 Replies

8. Shell Programming and Scripting

Coping files from server to local

This is my first post, so first I'd like to say hello to everyone. Here's the issue I'm having...I run a macro against multiple log files every morning. The procedure is sort of time consuming. I have to log into the box where there are stored, then ftp/download them to my local drive using... (3 Replies)
Discussion started by: jhofilena
3 Replies

9. Shell Programming and Scripting

For loop - coping with an asterisk item

How do you get a for loop to cope with one of the items being an asterisk? for myResult in `echo "*"` do echo "$myResult" done The asterisk is returning a file listing in the PWD. The same result can be got from: for myResult in "*" do echo "$myResult" done (1 Reply)
Discussion started by: PaulUrwin
1 Replies

10. UNIX for Dummies Questions & Answers

coping all files from a directory

Hello, i have a directory;say /home/pavi i has some files and every day files keep adding to it. i am writing a shell script which copies all the files from this directory to another.say /home/tom/tmp how do i copy all the files from /home/pavi to /home/tom/tmp all the files in the... (1 Reply)
Discussion started by: pavan_test
1 Replies
Login or Register to Ask a Question