Dear Monks,I have been facing a problem since last day ,but unable to get resolved it
It is my code
my $exp = Expect->spawn("telnet 192.168.1.150") or die "Cannot spawn telnet: $!\n";; my ($username,$password,$timeout); $username = 'ackerman'; $password = 1454; $timeout = 1; print localtime(time)."\n"; my $spawn_ok; $exp->expect($timeout, [ qr'login: $', sub { $spawn_ok = 1; my $fh = shift; $fh->send("$username\n"); exp_continue; } ], [ '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 );
And here is the output
[root@localhost Perl_Ping]# perl telnet.pl Mon Aug 26 11:48:21 2013 Trying 192.168.1.150... Connected to 192.168.1.150. Escape character is '^]'. User name: [root@localhost Perl_Ping]#
It is getting exit without taking username and password,don't know what's wrong ?I hope that you people will guide me through this
In reply to Telnet using Expect module by gaurav
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |