6 use Data::Dump qw/dump/;
8 die "usage: $0 [modem] commands\n" unless @ARGV;
10 my $modem = '10.0.0.138';
11 $modem = shift @ARGV if $#ARGV >= 1;
16 ':system config led=flash',
20 my ( $prompt, $default ) = @_;
21 warn "## ask $prompt [default]";
22 print "$prompt [$default] ";
25 $in = $default unless length($in) > 1;
31 next if (/^#/ || /^\s*$/);
33 warn "--$_--" if $debug;
34 $l =~ s/ask\(([^|\)]+)(?:\|([^\)]+))?\)/ask($1,$2)/eg;
35 warn "++ $l\n" if $debug;
39 push @commands, ':system config led=off';
41 warn "## connecting to $modem\n";
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 );
47 $exp->log_stdout( 1 );
49 my ( $username, $password ) = ('Administrator','');
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, '=>');
58 foreach my $cmd ( @commands ) {
59 $exp->send( "$cmd\r\n" );
60 $exp->expect($timeout, '=>');
63 $exp->send( "exit\r\n" );