The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Coping files from server to local jhofilena Shell Programming and Scripting 3 09-19-2007 02:50 PM
For loop - coping with an asterisk item PaulUrwin Shell Programming and Scripting 1 09-07-2007 03:01 AM
Cron won't run properly Steeler_fan UNIX for Dummies Questions & Answers 2 08-31-2006 10:32 AM
coping all files from a directory pavan_test UNIX for Dummies Questions & Answers 1 07-23-2006 05:35 AM
Coping filies from Linux Server to HP-UX Server cgege HP-UX 2 04-12-2004 01:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-19-2008
prashants prashants is offline
Registered User
  
 

Join Date: Jul 2008
Location: Pune,India
Posts: 2
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.

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 (permalink)  
Old 11-19-2008
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,576
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...
Closed Thread

Bookmarks

Tags
command, copy, copying

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0