/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 181 - (show annotations)
Tue Oct 30 14:45:17 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 1252 byte(s)
- fixed two argument invocation (modem, script)
- added usage when called without args
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Expect;
5 use Net::Telnet;
6 use Data::Dump qw/dump/;
7
8 die "usage: $0 [modem] commands\n" unless @ARGV;
9
10 my $modem = '10.0.0.138';
11 $modem = shift @ARGV if $#ARGV >= 1;
12
13 my @commands = (
14 ':system config led=flash',
15 );
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 while(<>) {
28 chomp;
29 next if (/^#/ || /^\s*$/);
30 my $l = $_;
31 warn "--$_--";
32 $l =~ s/ask\(([^|\)]+)(?:\|([^\)]+))?\)/ask($1,$2)/eg;
33 warn "++ $l\n";
34 push @commands, $l;
35 }
36
37 push @commands, ':system config led=off';
38
39 my $debug = 0;
40
41 warn "## connecting to $modem\n";
42
43 my $telnet = new Net::Telnet( $modem ) or die "Cannot telnet to $modem: $!\n";
44 my $exp = Expect->exp_init($telnet);
45 $exp->debug( $debug );
46
47 $exp->log_stdout( 1 );
48
49 my ( $username, $password ) = ('Administrator','');
50 my $timeout = 3;
51
52 $exp->expect($timeout, 'Username : ');
53 $exp->send("$username\r\n");
54 $exp->expect($timeout, 'Password :');
55 $exp->send("$password\r\n");
56 $exp->expect($timeout, '=>');
57
58 foreach my $cmd ( @commands ) {
59 $exp->send( "$cmd\r\n" );
60 $exp->expect($timeout, '=>');
61 }
62
63 $exp->send( "exit\r\n" );
64 $exp->soft_close();
65

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26