From: Kit S. <uni...@iw...> - 2003-06-17 20:05:43
|
I am having difficulty controling how expectperl is dumping output to the log file. i get the cat /etc/passwd like i desire but i also get the launching of bin/sh the prompt and the last which i do not desire (this is just a dummy program to solve the exact same problem in my larger one so ignore the why would you want to of the /usr/bin/last), i have tried everything i can think of and still no idea why it is broken, any thoughts? ----code----- #!/usr/bin/perl -w use strict; use Expect; $|++; #open STDERR, "/dev/null"; my $username="testuser"; my $password="password"; my $host="localhost"; my $timeout=4; my $exp = new Expect; #$exp->debug(3); $exp->log_file("/dev/null"); $exp->log_file(undef); print "Content-type: text/html\n\n<html>"; telnet_login($username,$password,$host,\$exp); $exp->expect($timeout, ['ncorrect', sub { print "<center>ERROR:<br>Login Incorrect, check username or password</center>\n"; &html_stop; die; } ], [timeout => sub { $exp->send("/bin/sh\n"); $exp->send("/usr/bin/last -5 $username\n"); $exp->clear_accum(); $exp->log_file(\&formatoutput); $exp->send("/bin/cat /etc/passwd\n"); $exp->log_file(undef); } ], ); $exp->soft_close(); print "</html>\n"; sub formatoutput { my $input = shift; chomp($input); $input =~ tr/\r//; $input =~ s|\n|<br>\n|g; print $input; } sub telnet_login { my ($username, $password, $host, $exp) = @_; $$exp->raw_pty(1); #treat this terminal as a raw file $$exp->log_stdout(0); #do not show terminal output to STDOUT $$exp->spawn("/usr/bin/telnet $host") || die "Cannot open telnet\n"; $$exp->expect(7, ['ogin:', sub { $$exp->send("$username\n"); exp_continue; } ], ['assword:', sub { $$exp->send("$password\n"); } ], [timeout => sub { die "<center>ERROR: <BR>A timeout has occured at login</center>\n"; } ], ); } |