Thread lesen/schreiben auf /dev/tty (6 answers)
Opened by Gast at 2007-03-20 13:49

davewood
 2007-03-21 17:10
#75150 #75150
User since
2007-03-21
3 Artikel
BenutzerIn
[default_avatar]
Hab nun einen Tag mit Expect gespielt :)
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/perl -w
use strict;
use warnings;
use Expect;

# command and parameters to execute
my $command = "sshfs";
my @params = ("user\@server:/home/user", "~/remote_home");

# data to be sent by expect
my $password = "********";

# spawn a new command
my $exp=new Expect();
$exp->debug(3); # 0,1,2,3
$exp->spawn($command, @params) || die "Error: Cannot spawn process. $!\n";

# wait for the password prompt
$exp->expect(5,-re=>'assword:') or die "No password prompt\n";
#print("\nError: " . $exp->error() . "\n");

# send password
$exp->send("$password\n");

$exp->soft_close();

exit(0);


Leider funktioniert das nicht

Debug Output
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
localuser@vigo:~/perl$ ./expect.pl
Spawned 'sshfs user@server:/home/user /home/localuser/home'
spawn id(3)
Pid: 8937
Tty: /dev/pts/1
at /usr/share/perl5/Expect.pm line 164
Expect::spawn('Expect=GLOB(0x8345394)', 'sshfs', 'user@server:/home/user', '/home/localuser/home') called at ./expect.pl line 17
Starting EXPECT pattern matching...
at /usr/share/perl5/Expect.pm line 533
Expect::expect('Expect=GLOB(0x8345394)', 5, '-re', 'assword:') called at ./expect.pl line 26
user@server's password: Closing spawn id(3).
at /usr/share/perl5/Expect.pm line 1311
Expect::soft_close('Expect=GLOB(0x8345394)') called at ./expect.pl line 32

Got EOF from spawn id(3).
spawn id(3) closed.
Pid 8937 of spawn id(3) exited, Status: 0x00
Closing spawn id(3).
at /usr/share/perl5/Expect.pm line 1388
Expect::hard_close('Expect=GLOB(0x8345394)') called at /usr/share/perl5/Expect.pm line 1578
Expect::DESTROY('Expect=GLOB(0x8345394)') called at ./expect.pl line 0
eval {...} called at ./expect.pl line 0
localuser@vigo:~/perl$
\n\n

<!--EDIT|davewood|1174489930-->

View full thread lesen/schreiben auf /dev/tty