/[cwmp]/google/tcli.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /google/tcli.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2 by dpavlin, Sat May 19 15:15:14 2007 UTC revision 3 by dpavlin, Sat May 19 15:45:05 2007 UTC
# Line 5  use Expect; Line 5  use Expect;
5  use Net::Telnet;  use Net::Telnet;
6    
7  my $modem = '192.168.1.254';  my $modem = '192.168.1.254';
8    my @commands = (
9    ':system config led=flash',
10    ':system config led=red',
11    ':system config led=off',
12    'exit',
13    );
14    
15    my $debug = 0;
16    
17  my $telnet = new Net::Telnet( $modem ) or die "Cannot telnet to $modem: $!\n";  my $telnet = new Net::Telnet( $modem ) or die "Cannot telnet to $modem: $!\n";
18  my $exp = Expect->exp_init($telnet);  my $exp = Expect->exp_init($telnet);
19    $exp->debug( $debug );
20    
21  my ( $username, $password ) = ('Administrator','');  my ( $username, $password ) = ('Administrator','');
22  my $timeout = 15;  my $timeout = 10;
23    
24  my $spawn_ok;  my $spawn_ok;
25  $exp->expect($timeout,  $exp->expect($timeout, 'Username : ');
26               [  $exp->send("$username\r\n");
27                qr'login: $',  $exp->expect($timeout, 'Password :');
28                sub {  $exp->send("$password\r\n");
29                  $spawn_ok = 1;  $exp->expect($timeout, '=>');
30                  my $fh = shift;  
31                  $fh->send("$username\n");  foreach my $cmd ( @commands ) {
32                  exp_continue;          warn "sending >> $cmd\n";
33                }          $exp->send( "$cmd\r\n" );
34               ],          $exp->expect($timeout, '=>');
35               [  }
36                'Password: $',  
               sub {  
                 my $fh = shift;  
                 print $fh "$password\n";  
                 exp_continue;  
               }  
              ],  
              [  
               eof =>  
               sub {  
                 if ($spawn_ok) {  
                   die "ERROR: premature EOF in login.\n";  
                 } else {  
                   die "ERROR: could not spawn telnet.\n";  
                 }  
               }  
              ],  
              [  
               timeout =>  
               sub {  
                 die "No login.\n";  
               }  
              ],  
              '-re', qr'[#>:] $', #' wait for shell prompt, then exit expect  
             );  

Legend:
Removed from v.2  
changed lines
  Added in v.3

  ViewVC Help
Powered by ViewVC 1.1.26