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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How do you copy files from CD Schnell SCO 2 10-01-2007 12:29 PM
copy of files bkan77 UNIX for Advanced & Expert Users 2 09-06-2007 03:53 AM
How to copy N files from one dir to another GMMike UNIX for Dummies Questions & Answers 1 10-13-2005 05:50 AM
copy files chirayus UNIX for Advanced & Expert Users 6 04-12-2004 08:56 AM
Copy all files 42!? UNIX for Dummies Questions & Answers 4 08-25-2002 09:05 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-21-2007
Registered User
 

Join Date: Feb 2007
Posts: 91
copy files from one dir to another

Hi ,
I want to copy files from one dir to anothe dir and check if destination dir exists ,if not exist ,has to create but when executing the below schell script ,the destination directory not exist and exit the shell script.
#!/bin/sh
src_path=/home/owngdw/abc
tgt_path=/home/owngdw/abc/xyz
if [ ! -d ${tgt_path}];
then
mkdir -p ${tgt_path}
#mkdir -p abc/xyz
fi
cp ${src_path}/aaa* ${tgt_path}/

Thanks
MR
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-21-2007
Registered User
 

Join Date: Feb 2006
Location: Mumbai, India
Posts: 24
Code looks ok..however one minor mistake I noticed maybe that helps

See below see if it works:

#!/bin/sh
src_path=/home/owngdw/abc
tgt_path=/home/owngdw/abc/xyz
if [ ! -d ${tgt_path} ];
then
mkdir -p ${tgt_path}
#mkdir -p abc/xyz
fi
cp ${src_path}/aaa* ${tgt_path}/

If not then let me know the error while executing it.
Reply With Quote
  #3 (permalink)  
Old 02-21-2007
Dhruva's Avatar
Registered User
 

Join Date: Mar 2006
Location: India
Posts: 241
What message you are getting i tried with same script and problem is
Code:
if [ ! -d ${tgt_path}];
here you need to maintain space between }<space>];

Code:
if [ ! -d ${tgt_path} ];
Reply With Quote
  #4 (permalink)  
Old 02-21-2007
Registered User
 

Join Date: Feb 2007
Posts: 91
Hi Anubhav,
Thanks for your help,now succeeded without an error.

Thanks and Regards,
MR
Reply With Quote
  #5 (permalink)  
Old 02-21-2007
Registered User
 

Join Date: Feb 2007
Posts: 91
comapre files

Hi,

one more query ,I have two files and want to compare and produce the o/p if any differences.Please anyone to help.

Thanks and Regards,
MR
Reply With Quote
  #6 (permalink)  
Old 02-21-2007
Registered User
 

Join Date: Feb 2006
Location: Mumbai, India
Posts: 24
well if there are plain files then you can use diff or sdiff for that. If you need something exact please provide the actual problem or mirror example for me to look.
Reply With Quote
  #7 (permalink)  
Old 02-21-2007
Registered User
 

Join Date: Feb 2007
Posts: 91
Hi ,
Ok,I will post u the scnerio later.However copying files and subdirectories between directories at specific time interval and want to prompt the destination directory name at run time ( Prompt the name ,when it enters that will check ,if it exists already exit and say that name already exist else create )

Thanks ,
MR
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0