/[cwmp]/google/trunk/scripts/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

Annotation of /google/trunk/scripts/tcli.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 130 - (hide annotations)
Fri Oct 26 18:12:10 2007 UTC (16 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 1197 byte(s)
added ask(prompt|default) in scripts to interactivly ask questions,
IP adress of modem is first (optional) param
1 dpavlin 2 #!/usr/bin/perl -w
2    
3     use strict;
4     use Expect;
5     use Net::Telnet;
6 dpavlin 130 use Data::Dump qw/dump/;
7 dpavlin 2
8 dpavlin 126 my $modem = '10.0.0.138';
9 dpavlin 130 $modem = shift @ARGV if $#ARGV > 1;
10    
11 dpavlin 3 my @commands = (
12     ':system config led=flash',
13     );
14 dpavlin 2
15 dpavlin 130 warn "ARGV = ",dump( $ARGV );
16    
17     sub ask {
18     my ( $prompt, $default ) = @_;
19     warn "## ask $prompt [default]";
20     print "$prompt [$default] ";
21     my $in = <STDIN>;
22     chomp($in);
23     $in = $default unless length($in) > 1;
24     return $in;
25     }
26    
27 dpavlin 4 while(<>) {
28     chomp;
29     next if (/^#/ || /^\s*$/);
30 dpavlin 130 my $l = $_;
31     warn "--$_--";
32     $l =~ s/ask\(([^|\)]+)(?:\|([^\)]+))?\)/ask($1,$2)/eg;
33     warn "++ $l\n";
34     push @commands, $l;
35 dpavlin 4 }
36    
37     push @commands, ':system config led=off';
38    
39 dpavlin 3 my $debug = 0;
40    
41 dpavlin 2 my $telnet = new Net::Telnet( $modem ) or die "Cannot telnet to $modem: $!\n";
42     my $exp = Expect->exp_init($telnet);
43 dpavlin 3 $exp->debug( $debug );
44 dpavlin 2
45 dpavlin 4 $exp->log_stdout( 1 );
46    
47 dpavlin 2 my ( $username, $password ) = ('Administrator','');
48 dpavlin 109 my $timeout = 3;
49 dpavlin 2
50 dpavlin 3 $exp->expect($timeout, 'Username : ');
51     $exp->send("$username\r\n");
52     $exp->expect($timeout, 'Password :');
53     $exp->send("$password\r\n");
54     $exp->expect($timeout, '=>');
55    
56     foreach my $cmd ( @commands ) {
57     $exp->send( "$cmd\r\n" );
58     $exp->expect($timeout, '=>');
59     }
60    
61 dpavlin 4 $exp->send( "exit\r\n" );
62     $exp->soft_close();
63    

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26