How can i 've the same dir structure?

  • delta32
  • Newbie
  • Newbie
  • delta32
  • Posts: 11

Post 3+ Months Ago

I 've a solaris machine and 've almost migrated to Linux.
but the problem is, i need to create the exact directory structure that i hve in the Solaris machine for most of my scripts to work.
Finding out a dir and its sub dir and its subdir and creating them is a tedious task.

Could some one throw some light into this, how can i 've the exact dir structure on the other machine.
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

My first question would be: Why are your scripts using hard coded paths?

Right off the bat, it sounds like you're either trying to do something wrong, or that you did something wrong before and now you have to fix it. What exactly is it you're trying to duplicate? Data directories, user directories or what?

Not to encourage you to do anything stupid (like copy your Solaris binaries over to your Linux machine and try to run them), but can you just connect through NFS and copy the desired folders over?
  • humbletech99
  • Proficient
  • Proficient
  • User avatar
  • Posts: 300

Post 3+ Months Ago

change your scripts, use env variables like you're supposed to...
  • delta32
  • Newbie
  • Newbie
  • delta32
  • Posts: 11

Post 3+ Months Ago

noo!, am not doin nythin unwanted niether 've done.
i just wanted to 've the same dir's i hve in my another machine to here...

like
/

dir1 dir2 dir3 dir4

dir11 dir12 dir21 dir22 dir31 dir32 dir 41 dir42


How will i hve the same dir tree in my other machine.?
i dont want the files in the dir. Jus the tree !

Hope am clear.?
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

oh, well that a little different: Why didn't you say so? ;)

The fastest way I know of would be to write a perl script, something like this should do it:
Code: [ Select ]
#!/usr/bin/perl
my $directory = "/path/to/directory";
open(FILE,">outfile.txt");
&read_directory($directory);
close FILE;

sub read_directory {
    my $directory = shift;

    opendir DIR, $directory or die "Cannot open Directory $!";
    my @files = readdir DIR;
    
    foreach my $el (@files){
        if( $el eq "." || $el eq ".." || !-d $directory.'/'.$el ){
            next;
        }
        &read_directory("$directory/$el");
        print FILE "$directory/$el\n";
    }
    closedir DIR;
}

exit;
  1. #!/usr/bin/perl
  2. my $directory = "/path/to/directory";
  3. open(FILE,">outfile.txt");
  4. &read_directory($directory);
  5. close FILE;
  6. sub read_directory {
  7.     my $directory = shift;
  8.     opendir DIR, $directory or die "Cannot open Directory $!";
  9.     my @files = readdir DIR;
  10.     
  11.     foreach my $el (@files){
  12.         if( $el eq "." || $el eq ".." || !-d $directory.'/'.$el ){
  13.             next;
  14.         }
  15.         &read_directory("$directory/$el");
  16.         print FILE "$directory/$el\n";
  17.     }
  18.     closedir DIR;
  19. }
  20. exit;

This will create a text file named outfile.txt which lists all of your directories with their complete paths. On the new server, you can then write a perl script to read all of those and create directories for each of them:
Code: [ Select ]
#!/usr/bin/perl
open(FILE,"outfile.txt");
my @data = <FILE>;
close FILE;
chomp(@data);
foreach my $el (@data);
    if( $el ne '' ){
        `mkdir $el`;
    }
}
exit;
  1. #!/usr/bin/perl
  2. open(FILE,"outfile.txt");
  3. my @data = <FILE>;
  4. close FILE;
  5. chomp(@data);
  6. foreach my $el (@data);
  7.     if( $el ne '' ){
  8.         `mkdir $el`;
  9.     }
  10. }
  11. exit;
  • humbletech99
  • Proficient
  • Proficient
  • User avatar
  • Posts: 300

Post 3+ Months Ago

I take it you're not interested in the contents of the directories etc, otherwise you'd need to try and symlink to the correct locations I think....
  • delta32
  • Newbie
  • Newbie
  • delta32
  • Posts: 11

Post 3+ Months Ago

thanks humble...

find . -type d --> did get me all the dirs

thanks for replying ..

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 42 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.