Using UNC paths and ssh with perl

Discussion in 'Perl Misc' started by amaccormack@gmail.com, Aug 16, 2005.

  1. Guest

    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)

    ---
    Any emails to (remove the
    XXYYZZ), please.
    , Aug 16, 2005
    #1
    1. Advertising

  2. Guest

    wrote in news:1124189558.316673.274180
    @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)
    >
    > ---
    > Any emails to (remove the
    > XXYYZZ), please.
    >
    >


    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)?
    , Aug 16, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tor Rest

    Copy using UNC paths

    Tor Rest, Aug 11, 2003, in forum: Perl
    Replies:
    1
    Views:
    3,731
    J├╝rgen Exner
    Aug 12, 2003
  2. =?Utf-8?B?U3RldmU=?=

    Directory.Exists() with UNC Network Paths

    =?Utf-8?B?U3RldmU=?=, Feb 11, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    755
    =?Utf-8?B?U3RldmU=?=
    Feb 11, 2006
  3. news.amnet.net.au

    ftp with java using UNC paths ?

    news.amnet.net.au, Feb 16, 2004, in forum: Java
    Replies:
    0
    Views:
    803
    news.amnet.net.au
    Feb 16, 2004
  4. Salim Fadhley
    Replies:
    0
    Views:
    264
    Salim Fadhley
    Aug 12, 2008
  5. LPaul

    Webhits and UNC Paths

    LPaul, Mar 23, 2010, in forum: ASP General
    Replies:
    1
    Views:
    756
    Evertjan.
    Mar 23, 2010
Loading...

Share This Page