CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
file creation

 



1951g
New User

Jun 16, 2008, 3:27 PM

Post #1 of 6 (2252 views)
file creation Can't Post

I want to write a perlscript that will traverse through a series of subdirectories and print out a dynamic string to a new file that will be executed separately from perlscript that created it. The perlscript would take 2 arguments: directory name and destination server. So if I passed the following 2 arguments to the perlscript:

/opt/oracle/oradata

destServerXYZ



It would generate the following in a file that I would execute later.

cp /opt/oracle/oradata01/redo1.dbf

cp /opt/oracle/oradata01/control1.dbf

cp /opt/oracle/oradata02/redo1.dbf

cp /opt/oracle/oradata03/subdir/usertablespace.dbf

Is there a good way to do this with a perlscript so no matter what server I'm on or directory structure I give, it'll start at the top level of the directory I give and traverse through subdirectories and files to construct the cp statements?



Thanks for any help with this.


KevinR
Veteran


Jun 16, 2008, 5:03 PM

Post #2 of 6 (2246 views)
Re: [1951g] file creation [In reply to] Can't Post

If you want to traverse a directory and all of its subdirectories use the File::Find module.
-------------------------------------------------


meloyelo
User

Jun 16, 2008, 10:40 PM

Post #3 of 6 (2241 views)
Re: [1951g] file creation [In reply to] Can't Post

The cp commands you show are not complete - they only have one argument. How is destServerXYZ part of what you want to do?

Also, you might be able to do this with just the Unix find utility:

find /opt/oracle/oradata -name '*.dbf' -exec echo cp '{}' ... ';'


1951g
New User

Jun 17, 2008, 6:47 AM

Post #4 of 6 (2233 views)
Re: [meloyelo] file creation [In reply to] Can't Post

Yes, I accidentially left off the last part. Actually, I'm going to be using rsync instead of cp since I'm going from 1 server to another keeping same directory structure but wanted to be able to use this perlscript as a utility to run on any server giving it the 2 arguments to construct the directories.

rsync /opt/oracle/oradata01/redo1.dbf destinationserver:/opt/oracle/oradata01/redo1.dbf

rsync /opt/oracle/oradata01/control1.dbf destinationserver:/opt/oracle/oradata01/control1.dbf

rsync /opt/oracle/oradata02/redo1.dbf destinationserver:/opt/oracle/oradata02/redo1.dbf

rsync /opt/oracle/oradata03/subdir/usertablespace.dbf destinationserver:/opt/oracle/oradata03/subdir/usertablespace.dbf

Thanks.


1951g
New User

Jun 17, 2008, 6:48 AM

Post #5 of 6 (2232 views)
Re: [KevinR] file creation [In reply to] Can't Post

Kevin,



Thanks for the help. That's enough to get me going in the right direction.


meloyelo
User

Jun 17, 2008, 8:04 AM

Post #6 of 6 (2228 views)
Re: [1951g] file creation [In reply to] Can't Post

You may not have to write any perl at all -- rsync has the capability to perform recursive copies and also to match file names (see the --include and --exclude options.)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives