Using UNC paths and ssh with perl

A

amaccormack

I'm trying to set up various XP machines (all with cygwin installed and
sshd running) on our network so that I can run a bunch of regression
tests networked across them. Now, I dont want to have to bother logging
in to each one by hand and adding networked drives that match my own
machine, so I though I could use UNC paths. Here's what I came up with:

sub uncpath {
my $orig_dir = shift;

$orig_dir = `cygpath -m $orig_dir`;
chomp $orig_dir;
if ($orig_dir =~ /^([A-Z])\:/i) {
my $drive = $1;
open GETUNC, "net use|";
NETUSE: while (<GETUNC>) {
if (/^OK\s+$drive\:\s+(\S+)/i) {
my $unc = $1;
$unc =~ s|\\|/|g;
$orig_dir =~ s|$drive\:|$unc|i;
last NETUSE;
}
}
}
return $orig_dir;
}

Maybe there's a better way, but this does seem to work. However, when I
ssh to another machine, it cannot find the UNC path until there is at
least one drive mapped to the server... e.g.

me@mybox ~ ls //serv1/x/y/z
....runs OK...
me@anotherbox ~ ls //serv1/x/y/z
ls: reading directory //serv1: bad file descriptor
me@anotherbox ~ net use z: \\\\serv1\\some\\other\\path
me@anotherbox ~ ls //serv1/x/y/z
....now runs OK...

So, I wondered if there was an easy way to force the other machine to
know abour serv1? I can always put a net use command in my startup
script, but that seems too hacky (although the hackiness is already way
more than I'd like)
 
G

Guest

(e-mail address removed) wrote in @z14g2000cwz.googlegroups.com:
I'm trying to set up various XP machines (all with cygwin installed and
sshd running) on our network so that I can run a bunch of regression
tests networked across them. Now, I dont want to have to bother logging
in to each one by hand and adding networked drives that match my own
machine, so I though I could use UNC paths. Here's what I came up with:

sub uncpath {
my $orig_dir = shift;

$orig_dir = `cygpath -m $orig_dir`;
chomp $orig_dir;
if ($orig_dir =~ /^([A-Z])\:/i) {
my $drive = $1;
open GETUNC, "net use|";
NETUSE: while (<GETUNC>) {
if (/^OK\s+$drive\:\s+(\S+)/i) {
my $unc = $1;
$unc =~ s|\\|/|g;
$orig_dir =~ s|$drive\:|$unc|i;
last NETUSE;
}
}
}
return $orig_dir;
}

Maybe there's a better way, but this does seem to work. However, when I
ssh to another machine, it cannot find the UNC path until there is at
least one drive mapped to the server... e.g.

me@mybox ~ ls //serv1/x/y/z
...runs OK...
me@anotherbox ~ ls //serv1/x/y/z
ls: reading directory //serv1: bad file descriptor
me@anotherbox ~ net use z: \\\\serv1\\some\\other\\path
me@anotherbox ~ ls //serv1/x/y/z
...now runs OK...

So, I wondered if there was an easy way to force the other machine to
know abour serv1? I can always put a net use command in my startup
script, but that seems too hacky (although the hackiness is already way
more than I'd like)

you might try using ls \\serv1\x\y\z or maybe \\\\serv1\\x\\y\\z
depending on quoting/escaping
(i.e. use backslashes - depending on your implementation of perl, this
may work)
On my machine right now, using forward slashes fails, but backslashes
works. I'm not sure why - maybe the backslashes are passed on to XP
differently than forward slashes. I suspect that slashes are converted
to backslashes when passing the path to XP. Perhaps the difference is
that perl uses native functions if forward slashes are used, but using
backwards slashes makes it pass the job on to the OS (I'm just guessing
here)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top