Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

split function

Status
Not open for further replies.

rickict

IS-IT--Management
Apr 29, 2005
18
GB
can anyone help
im after a quick solution to a problem at work. i wont bore you with details but i need to get the names of all the shares on a server into a file so i can add them to a .bat
file with the xcopy function.

with my little knowledge i managed to send the out put of the windows command "net view \\server" to a file net.log
then i thought ill use perl to take out all the junk and leave just share names then print them to a .bat with a
xcopy command for each share. as per the script below.

the problem im having is cutting out the unwanted stuff.
mainly white space new lines and the word Disk.

theres probably a much better way to do this!! any help either way would be great. thanks



#! usr/bin/perl -w

open FH, 'net.log';

@file=<FH>;

open (FILE,'>backup.bat');
select FILE;

foreach(@file){

@shares=split(m/\s+\n/, $_);

foreach(@shares){
@shares2=split(m/\s+Disk+/, $_);

print "xcopy /S \\\\rnb-pc-server\\@shares2 d:\\backup\\@shares2\n";
}
}
close FH;
close FILE;

 
can you give an example of the net.log file


Kind Regards
Duncan
 
Code:
print "xcopy /S \\\\rnb-pc-server\\@shares2 d:\\backup\\@shares2\n";

Code:
foreach (@shares2) {
  print "xcopy /S \\\\rnb-pc-server\\$_ d:\\backup\\$_\n";
}

HTH
--Paul

cigless ...
 
this is the output from my home but my work has over a thousand shares on one server( i didn't set this up)

the headers and the bit a the bottom i can remove easily by hand. it just the "type" "used as" and "comments" fields that i need to remove.

............................................................

Shared resources at \\rnb-pc-server



Share name Type Used as Comment

-------------------------------------------------------------------------------
EPSONSty Print EPSON Stylus C60 Series
Linux_on_G Disk Disk
my_Documents Disk Disk
The command completed successfully.

..........................................................


thanks (how do i create those code boxes like paulTEG's done?
ps
also i dont understand paulTEG's reply thanks anyway.
 
bit like html - just use square brackets instead of < and >

... and use the word 'code' inside


Kind Regards
Duncan
 
Does this help?

... Paul may well have answered your question already - i am unsure as i don't use a PC

Code:
[b]#!/usr/bin/perl[/b]

@lines = <DATA>;

foreach $line (@lines) {
  if ($line =~ m/^([^ ]+) +Disk/) {
    print "$1\n";
  }
}

__DATA__
Share name    Type   Used as  Comment                  

-------------------------------------------------------------------------------
EPSONSty      Print           EPSON Stylus C60 Series  
Linux_on_G    Disk            Disk                         
my_Documents  Disk            Disk                        
The command completed successfully.

..........................................................


Kind Regards
Duncan
 
perfect, thanks very much for your help.
this is the final result. works great.

Code:
#!/usr/bin/perl

open FH, 'net.log';

@shares = <FH>;

open (FILE,'>backup.bat');
select FILE;

foreach $junk (@shares) {
  if ($junk =~ m/^([^ ]+) +Disk/) {
   
     print "xcopy /S \\\\rnb-pc-server\\$1\\ c:\\backup\\$1\\\n";


}
}
close FH;
close FILE;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top