#! perl -wl my %net_use; foreach (net_use()) { push @{$net_use{uc $_->[1]}}, $_; } # use Data::Dumper; # print Dumper \%net_use; @ARGV or @ARGV = keys %net_use; foreach my $drive (@ARGV) { $drive =~ s/^([a-z]):?$/\U$1:/i or $drive = ''; if(my $ary = $net_use{$drive}) { print STDERR "Processing $drive"; foreach my $connect (@$ary) { unless($connect->[0] =~ /\bok\b/i) { my $cmd = "net use $connect->[1] \"$connect->[2]\""; print STDERR $cmd; system($cmd) and print ' FAILED'; } } } else { print STDERR "Skipping $drive"; } } sub net_use { # return a data structure parsing the info from NET USE my @net = grep /\S/, `net use`; # parse the title (after searching for the underline line and using the line in front of it) to extract table structure my($hr) = grep $net[$_] =~ /^([^\s\w])\1+$/, 1 .. $#net; my @right; while($net[$hr-1] =~ /\S+(?:\ \S+)*/g) { push @right, $-[0]; } $right[0] = 0; # drop title and underline splice @net, 0, $hr+1; # process lines my $unpack = join '', map "A$_", map($right[$_]-$right[$_-1], 1 .. $#right), '*'; # print $unpack; return grep $_->[2] =~ /^\\\\/, map [ unpack $unpack, $_ ], @net; }