morgon has asked for the wisdom of the Perl Monks concerning the following question:

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!

Replies are listed 'Best First'.
Re: Problem with Expect
by salva (Canon) on Mar 12, 2015 at 09:52 UTC