Hi

I try to automate mounting a directory from my phome to my laptop via sshfs.

Authentication is via password and that is where I have the problem:

use Expect; $Expect::Exp_Internal = 1; # for debugging my $cmd = Expect->spawn('/usr/bin/sshfs', 'root@moto:/mnt/sdcard/eBook +s', 'mnt') or die $!; $cmd->expect(undef, 'root@moto\'s password: '); $cmd->send("XXXX\n");
This is the output:
Spawned '/usr/bin/sshfs root@moto:/mnt/sdcard/eBooks mnt' spawn id(3) Pid: 11716 Tty: /dev/pts/2 at /home/mh/perl5/perlbrew/perls/perl-5.18.1/lib/site_perl/5.18.1/Exp +ect.pm line 181. Expect::spawn('Expect', '/usr/bin/sshfs', 'root@moto:/mnt/sdcard/e +Books', 'mnt') called at ./mnt.pl line 11 Starting EXPECT pattern matching... at /home/mh/perl5/perlbrew/perls/perl-5.18.1/lib/site_perl/5.18.1/Exp +ect.pm line 561. Expect::expect('Expect=GLOB(0xfe0ab8)', undef, 'root@moto\'s passw +ord: ') called at ./mnt.pl line 12 spawn id(3): list of patterns: #1: -ex `root@moto\'s password: ' spawn id(3): Does `' match: pattern #1: -ex `root@moto\'s password: '? No. Waiting for new data (unlimited seconds)... root@moto's password: spawn id(3): Does `root@moto\'s password: ' match: pattern #1: -ex `root@moto\'s password: '? YES!! Before match string: `' Match string: `root@moto\'s password: ' After match string: `' Matchlist: () Returning from expect successfully. Sending 'XXXX\n' to spawn id(3) at /home/mh/perl5/perlbrew/perls/perl-5.18.1/lib/site_perl/5.18.1/Exp +ect.pm line 1264. Expect::print('Expect=GLOB(0xfe0ab8)', 'XXXX\x{a}') called at ./mn +t.pl line 13
(I've edited the password out both in the code and the output).

So it seems that it works but when I try to access the directory I get the error "ls: cannot access mnt: Transport endpoint is not connected".

I can do the mounting with no problem manually so it must be something in the script I am doing wrong...

Can someone help me here?

Many thanks!


In reply to Problem with Expect by morgon

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.