From: Austin S. <te...@of...> - 2003-04-22 18:44:44
|
On Tue, Apr 22, 2003 at 12:26:32PM -0600, Ed Arnold wrote: > I've attached two short scripts to this email: > > o "expsu" is an expect/tcl program which su-s to another user. It works > correctly. > o "explsu" is a perl program which attempts to do the same thing with > the Expect module. It doesn't work; it sees the shell prompt, but it > exits prematurely somewhere in interact(). > What output have you gotten from turning on debug and exp_internal? What platform are you running this on? I don't see any obvious bugs - at first glance it looks like it should run just fine. Austin > Is there something I need to change/add in explsu to make it work, or is > this a bug in perl's Expect module? > #!/usr/local/bin/expect > > set user test > set pasw pop,eye > set send_slow { 1 .1 } > spawn /bin/su $user > expect -re "Password: " > send -s "$pasw\r" > > interact { > } > #!/local/s/perl/bin/perl > > use Expect; # www.cpan.org: Expect-1.15, IO-Stty-.02, IO-Tty-1.02 > use IO::Stty; > > $ENV{PATH} = "/bin"; $ENV{SHELL} = "/bin/sh"; > my $user = "test"; > my $passwd = "pop,eye"; > my $exp = new Expect(); > #$exp->manual_stty(1); > #$ostty = IO::Stty::stty(\*STDIN,'-g'); > $exp->slave->clone_winsize_from(\*STDIN); > $exp->log_stdout(0); > $exp->exp_internal(0); > $Expect::Debug = 0; > #$exp->raw_pty(1); # don't go there > $exp->spawn("/bin/su",$user); > $expstr = "Password: "; > $exp->expect(4,$expstr); > $got = $exp->exp_match(); print "$expstr TILT!\n" if $got ne $expstr; > $exp->send_slow(0.1,"$passwd\r\n"); > $expstr = "\$ "; > $exp->expect(4,$expstr); > $got = $exp->exp_match(); print "$expstr TILT!\n" if $got ne $expstr; > print "$expstr"; # print sh prompt and interact > $exp->interact(); |