2

I am trying to open a telnet connection, execute some command, and terminate the connection. I need it to run around 1000 times. The script runs fine for some number of attempts [ say around 23 - 25 ]. Then, I get the following error:

"pattern match read eof at perlscript.pl line 23"

The line 23 corresponds to the code

$tn->waitfor('/Password: /i').

After this error, if I try to open the telnet connection manually, I get an error:

"Service and queue are full. Please come back later"

I guess I get that first error "pattern match read eof" because the telnet connection is terminating because of the "Service and queue are full" error.

I was trying to debug more into the issue and when I checked the logs, I came across this error:

2012 08 08 10:27:46 EDT: Exception occured:
java.lang.NullPointerException
at dtw.telnetd.net.Connection.close(Connection.java)
at dtw.telnetd.net.ConnectionManager.cleanupBroken(ConnectionManager.java)
at dtw.telnetd.net.ConnectionManager.run(ConnectionManager.java)

Any idea on what could be causing this Exception?

r9891
  • 3,163
  • 1
  • 14
  • 12
  • My first advice is to check the logs on the server. My second to to make sure your Perl script _do_ close the connections properly (i.e. send proper logout and such). – Some programmer dude Aug 08 '12 at 10:27
  • I am using `$tn->close();` command to close the connection. I have used `sleep 1` command after the execution of each command so that the previous command gets enough time to complete. I am not sure which logs I can check on the server. Can you please tell me... – r9891 Aug 08 '12 at 10:36
  • Before closing the connection you should probably send a "logout" command. This will make the server close it's connection. The log you should check is probably the system log, and can be found in `/var/log/` on the server machine, either as the file `syslog` or `messages` or something similar. – Some programmer dude Aug 08 '12 at 10:43
  • I used `$tn->cmd("logout");` but I got an error for that. So I used `$tn->cmd("exit");` but to no avail. I got the same error "Pattern match read eof". I checked the log file and it looks fine. I just run the script again. It ran for 1230 times before terminating. I am not sure what's going wrong! – r9891 Aug 08 '12 at 11:15
  • http://stackoverflow.com/questions/12596014/telnet-automation-script-fails-sometimes similar problem. Not yet resolved. Any suggestions? – Ram Dec 19 '12 at 07:12

1 Answers1

0
#!/usr/bin/perl

($user,$pass)=@ARGV;
use Data::Dumper;
%resp=();
use Net::Telnet ();
for (0..100) {
$tn=new Net::Telnet(Timeout=>10, prompt=>'/jamie\@jenks:~\$/');
$tn->open("jenks");
$tn->login($user,$pass);
@lines=$tn->cmd("uname -a");
$resp{$lines[0]}++;
$tn->prompt("//");
@bye=$tn->cmd("logout");
}

print Dumper(\%resp);

This seems to work for me, setting the prompt to a null string before the logout command is issued

Vorsprung
  • 32,923
  • 5
  • 39
  • 63