I am writing a script where I ssh to remote hosts, where I mount a smb share, cd to the scripts directory on that share, and run a perl script. (The perl script is a TCPClient and connects to the script running on the local host). I am using Net::OpenSSH to ssh from my local linux host to a remote linux host:
my $ssh = Net::OpenSSH->new( $ip, master_opts => [-o => "StrictHostKeyChecking=no"], password=>$password, user => $user);
my resulting remote client object contains my ssh object:
client obj: $VAR1 = bless( { 'hostname' => 'qaclient6.omneon.local', 'ip' => '10.4.96.106', 'os' => 'linux', 'password' => 'passwd', 'ssh' => bless( { '_batch_mode' => undef, '_ctl_path' => '/root/.libnet-opens +sh-perl/root-10.4.96.106-27838-53771', '_default_argument_encoding' => und +ef, '_default_ssh_opts' => undef, '_default_stderr_fh' => undef, '_default_stdin_fh' => undef, '_default_stdout_fh' => undef, '_default_stream_encoding' => undef +, '_error' => 0, '_error_prefix' => [], '_expand_vars' => undef, '_external_master' => undef, '_gateway_args' => undef, '_home' => '/root', '_host' => '10.4.96.106', '_host_squared' => '10.4.96.106', '_key_path' => undef, '_kill_ssh_on_timeout' => undef, '_login_handler' => undef, '_master_opts' => [ '-o', 'StrictHostKeyC +hecking=no' ], '_master_stderr_discard' => undef, '_master_stderr_fh' => undef, '_master_stdout_discard' => undef, '_master_stdout_fh' => undef, '_mpty' => bless( \*Symbol::GEN1, ' +IO::Pty' ), '_passphrase' => undef, '_passwd' => '@BAJ@A"', '_perl_pid' => 27838, '_pid' => 27840, '_port' => undef, '_proxy_command' => undef, '_rsync_cmd' => 'rsync', '_scp_cmd' => undef, '_ssh_cmd' => 'ssh', '_ssh_opts' => [ '-l', 'root' ], '_target_os' => 'unix', '_thread_generation' => 0, '_timeout' => undef, '_user' => 'root', '_vars' => {}, '_wfm_bout' => '' }, 'Net::OpenSSH' ), 'user' => 'root' }, 'MGRemoteHost' );
then I mount a smb share on the remote host with the command:
my $cmd = 'mount -t cifs //$server->ip}/myscripts /mnt/mgscripts -o us +er=qauser,password=Tester-01'; push @cmds,$cmd; $ssh->open_ex( { stdin_pipe => 1,stdout_pipe => 1, stderr_pipe => 1 }, + @cmd ) or my $error = "open_ex failed: " . $opts->{ssh}->error;
I can see the mount is successful via another ssh session to the remote host, where I can cd to a directory on the mount point. Then I send the command:
"cd /mnt/mgscripts/latest' via open_ex and I get: 'bash: line 0: cd: /mnt/mgscripts/latest: No such file or directory'
So to simplify, I stopped doing the mount in the script and used the mount point that the script already created on the previous run. This is what mount shows:
'//10.20.56.64/myscripts/ on /mnt/mgscripts type cifs (rw,mand)'
However if issue this command via open_ex:
'cd /mnt/mgscripts/latest;ls'
It works! So I thought, OK, since what I want to do is mount a share, cd to it then run a perl script, this command should work: 'mount;cd /mnt/mgscripts/latest;perl CreateFiles -fspath=/mnt/qa5' Yes! it worked. Then I tried it again... Nope! I got:
$VAR1 = [ 'bash: line 0: cd: /mnt/mgscripts/latest: No such file or di +rectory', 'Can\'t open perl script "CreateFiles.pl": No such file or d +irectory' ];
So I kept testing and I found that the commands work (both the "mount;cd ...;ls" and the "mount;cd ...;perl...") exactly every other run of the script. I tried putting sleeps in between the commands:
'mount;sleep 10;cd /mnt/mgscripts/latest;sleep 10;ls'
but that didn't help either.
Note that the script always succeeds if I use a mount point on the remote host that was not created via Net::OpenSSH but just a ssh session from my local linux host.
'//10.20.56.64/myscripts/ on /mnt/mgscripts type cifs (rw,mand)'
Any ideas about what could be happening? Thanks, cebundy

In reply to Net::OpenSSH: Trouble accessing a mount point mounted via the perl script by cebundy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.