I can use expect scripts to connect one device and deal with multi pages lisk "---MORE---" by press Space to continue.but if fails when i want use While to deal with multi-pages.
my question: (1) why the scripts can not run the While(1) part (2) what about the error: * at /usr/local/share/perl/5.8.8/Expect.pm line 1264 Expect::print('Expect=GLOB(0x834e748)', 'show product-info\x{a}') called at ./expect_tst.pl line 26* Expect scripts ------------------------------------------------------------------- #!/usr/bin/expect -f if { $argc != 3 } { send_user "usage: get_hwrtne_conf.exp ip user password\n" exit } set timeout 1 set TERM ANSI set SERVER [lindex $argv 0] set USERNAME [lindex $argv 1] set PASSWD [lindex $argv 2] spawn telnet expect "telnet> " send "open $SERVER\r" sleep 1 expect "login:" send "$USERNAME\r" sleep 1 expect "Password:" send "$PASSWD\r" sleep 1 expect "*>" send "show product-info\r" while (1) { sleep 1 expect { "*MORE*" { send " " } "*>" { break } } } send "quit\r" interact ----------------------------------------------------------------- Perl Script: ------------------------------------------------------------------- use Expect; use strict; my $exp = new Expect; sleep(1); $exp->raw_pty(1); #$exp->log_stdout(0); my $exp = Expect->spawn("telnet 192.168.1.1"); $exp->exp_internal(1); $exp->debug(3); $exp->log_file("out","w"); sleep(2); $exp->send("root\n"); sleep(1); $exp->expect("Password"); sleep(1); $exp->send("password\n"); $exp->expect("cli>"); sleep(1); $exp->send("show product-info\n"); while(1){ sleep(1); print "<--=\n"; $exp->expect( [ qr/--MORE--/i,sub{ my $self =shift; $self->send_slow(" "); exp_continue; } ], [qr'cli>',{ last } ]); } #$exp->debug(); $exp->soft_close(); ------------------------------------------------------------------------------------- Debug info: ------------------------------------------------------ debian:~# ./expect_tst.pl Sending 'root\n' to spawn id(5) at /usr/local/share/perl/5.8.8/Expect.pm line 1264 Expect::print('Expect=GLOB(0x834e748)', 'root\x{a}') called at ./expect_tst.pl line 18 Starting EXPECT pattern matching... at /usr/local/share/perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0x834e748)', 'Password') called at ./expect_tst.pl line 20 spawn id(5): list of patterns: spawn id(5): Does `' match: Trying 192.168.1.1... Connected to 192.168.1.1. Escape character is '^]'. root spawn id(5): Does `Trying 192.168.1.1...\r\nConnected to 192.168.1.1.\r\nEscape character is \'^]\'.\r\nroot\r\n' match: Sending 'password\n' to spawn id(5) at /usr/local/share/perl/5.8.8/Expect.pm line 1264 Expect::print('Expect=GLOB(0x834e748)', 'password\x{a}') called at ./expect_tst.pl line 22 Starting EXPECT pattern matching... at /usr/local/share/perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0x834e748)', 'cli>') called at ./expect_tst.pl line 24 spawn id(5): list of patterns: spawn id(5): Does `Trying 192.168.1.1...\r\nConnected to 192.168.1.1.\r\nEscape character is \'^]\'.\r\nroot\r\n' match: BusyBox on localhost login: root Password: spawn id(5): Does `Trying 192.168.1.1...\r\nConnected to 192.168.1.1.\r\nEscape character is \'^]\'.\r\nroot\r\n\r\nBusyBox on localhost login: root\r\nPassword: ' match: Sending 'show product-info\n' to spawn id(5) at /usr/local/share/perl/5.8.8/Expect.pm line 1264 Expect::print('Expect=GLOB(0x834e748)', 'show product-info\x{a}') called at ./expect_tst.pl line 26 <--= Closing spawn id(5). at /usr/local/share/perl/5.8.8/Expect.pm line 1354 Expect::soft_close('Expect=GLOB(0x834e748)') called at ./expect_tst.pl line 42 DSL Modem CLI Copyright (c) 2004 Texas Instruments, Inc. cli> show product-info Product Information Model Number : AR7WRD HW Revision : 01000008-02010202 Serial Number : none USB PID : N/A USB VID : N/A Ethernet MAC : 00:08:5C:7B:9B:78 DSL MAC : 00:08:5C:7B:9B:7A USB MAC : N/A USB Host MAC : N/A AP MAC : 00:08:5C:7B:9B:79 Software Versions Gateway : 3.7.0B ATM Driver : 20.1 (6.00.01.00-370B.060526) DSL HAL : 6.00.01.00 DSL Datapump : 6.00.04.00 Annex A SAR HAL : 01.07.2b PDSP Firmware : 0.54 --MORE--Timed out waiting for an EOF from spawn id(5). spawn id(5) closed. Pid 12929 of spawn id(5) exited, Status: 0x01 Closing spawn id(5). at /usr/local/share/perl/5.8.8/Expect.pm line 1431 Expect::hard_close('Expect=GLOB(0x834e748)') called at /usr/local/share/perl/5.8.8/Expect.pm line 1621 Expect::DESTROY('Expect=GLOB(0x834e748)') called at ./expect_tst.pl line 0 eval {...} called at ./expect_tst.pl line 0