why "Bad file descriptor at line 94 "

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default why "Bad file descriptor at line 94 "

    Hi all,

    Can someone give me a hand understanding why I am getting this error.

    This script telnets into a telnet server (cisco) then telnets into other
    cisco router to grab there configs. I get these errors when trying to
    connect to certain routers (5, 11,12,13,14). If I look in my dump logs I see
    that the device didn't echo anything back. I have play with some control and
    break commnads wich help but doesn't fix all of them. I have a feeling it
    has something to so with the filehandle or buffer but not sure.

    Either case can anyone tell me why I am getting Bad file descriptor at line
    94 ?? I have the line marked ****

    This is my first perl script so please don't laugh ;-(


    This is ussing active state on an XP machine.
    This is perl, v5.6.1 built for MSWin32-x86-multi-thread
    (with 1 registered patch, see perl -V for more detail)

    thanks for any help

    #!/perl/bin/



    # Uses Net::Telnet::Cisco module

    # Uses Net::Telnet module

    # Uses Time-local module



    ## **My $vars

    $host = "10.4.1.10";

    $TFTPSERVER = "10.4.1.238";

    $username = "user";

    $password = "pass";

    $enpassword = "pass";

    $filename = "dump.txt";

    $file = "input.txt";

    $errorlogfilelast = "c:/perl/bin/myerrorloglast.txt";

    $errorlogfileall = "c:/perl/bin/myerrorlogall.txt";

    $count = 1;

    $termconfg = "term1-confg";

    $secs = 25; # Timeout when sending
    commnads If its a slow router with a big config this could take time

    $match = "Term1";

    $port = 2005;

    $line = $port - 2000;

    $error = 0;

    $totalerrors = 0;

    $RYT = 10;

    $Xsec = 2; # Pause before sending
    command to router 2 seconds is to slow

    $mycommand = "show run";

    $maxportrange = 2015; # put things you don't whant affected at the end





    # system("cls");

    $thetime = localtime();

    print "\nStarting program at $thetime\n";









    use Net::Telnet::Cisco;

    $session = Net::Telnet::Cisco->new(

    Host => $host,

    Dump_Log =>
    "c:/perl/bin/".$filename,

    Input_log => "c:/perl/bin/".$file,

    Timeout =>
    $secs);



    # Conect to Term server



    $session->login(Name => $username,

    Password => $password);

    print "\nLoged into Term router as username: $username\n";



    $session->enable($enpassword);

    #print "Enable mode on Term\n";

    print "Clearing line: ";

    while ($count < 17) { # Clear all TTY
    and 4 vty

    $session->cmd("clear line $count\n");

    print "$count ";

    $count = $count + 1;

    }

    print "\nFinished disconecting all lines\n";



    $session->close;

    ################################################



    while ($port <= $maxportrange) {



    print
    "\n\nooooooooooooooooooooooooooooooooooooooooooooo oooooooooooooooooooooooooo
    oooo \n\n";

    # $file = "input.txt" + '$line';

    print "\nOutput filesname is router$line.txt, Time is
    $thetime\n";



    use Net::Telnet::Cisco;

    $session = Net::Telnet::Cisco->new(

    Host => $host,

    Port => $port,

    Dump_Log =>
    "c:/perl/bin/routerdump".$line.".txt",

    Input_log =>
    "c:/perl/bin/router".$line.".txt",

    Timeout =>
    $secs,

    Errmode => sub {


    #print "\n\n!!Bad command ? ". "port: $port!!!!! $! \n";


    $error = $error + 1; # 1 means error has occurred.

    warn
    $!; # option are die return and warn ***THIS IS LINE 94 *************

    }

    );



    #WAIT FOR A FEW SECONDS

    $wait = time() + $Xsec;

    print "\nGetting ready to log into Line:$line, Port:$port - ";

    while (time () < $wait) {

    }



    $session->cmd("!\n"); #these lines are
    out of desperation tryint to figure out why this works sometimes

    $session->cmd("!\n"); # some routers
    respond some don't code and versions are amess but seem unrelated

    $session->cmd("!\n");

    $session->cmd("!\n");

    $session->send_wakeup( 'connect' ); #
    fixes line 5 11 12

    $session->send_wakeup( 'connect' ); #
    fixes line 5 11 12

    $session->send_wakeup( 'connect' ); #
    fixes line 5 11 12

    $session->send_wakeup( 'connect' ); #
    fixes line 5 11 12

    $session->cmd("!\n");

    $session->ios_break;

    $session->cmd("!\n");

    $session->send_wakeup( 'connect' ); #
    fixes line 5 11 12

    $session->cmd("!\n");

    $session->cmd("!\n");

    $session->cmd('terminal length 0');





    $session->cmd('terminal length 0'); # default is 24

    if ($error < 1){

    #Conect to LineX

    # $session->cmd("disable\n");

    $session->login(Name => $username,

    Password => $password);

    $session->enable($enpassword);

    print "Loged into LINE:$line \n";

    print "Getting ver from device attached
    to line : $line - ";

    $session->cmd($mycommand);

    print "Done with Line:$line\n";

    $session->cmd('terminal length 24'); #
    default is 24

    $port = $port +1;

    $line = $line +1;

    } else {

    print "E";

    $session->close;

    $totalerrors = $totalerrors
    + 1;

    if ($totalerrors > 4 )
    {


    open(MYERRORLOGOUTLAST, ">>$errorlogfilelast");


    print MYERRORLOGOUTLAST "Connection failed for ". "port: $port at Time =
    $thetime\n";


    close(MYERRORLOGOUTLAST);


    $error = 0; # reset error level to none


    print "failed and increaseing port count";


    $port = $port +1;


    $line = $line +1;


    } else {


    }

    }







    $session->close;

    }

    print
    "\n\nooooooooooooooooooooooooooooooooooooooooooooo oooooooooooooooooooooooo\n
    \n";

    ################################################## ###########





    print "\n Exiting the program on $thetime \n";

    print "\nThe proagram finished with $totalerrors errors.\n";

    if ($totalerrors > 0) {

    open(MYERRORLOGINLAST,
    "$errorlogfilelast");

    @myerrorlogstufflast =
    <MYERRORLOGINLAST>;

    print "The following files have errors
    in them\n";

    print @myerrorlogstufflast;

    } else {

    open(MYERRORLOGOUTLAST,
    ">$errorlogfilelast");

    print MYERRORLOGOUTLAST "No
    errors occurred on $thetime\n";



    open(MYERRORLOGOUTALL,
    ">>$errorlogfileall");

    print MYERRORLOGOUTALL "No
    errors occurred on $thetime\n";

    close(MYERRORLOGOUTLAST);

    close(MYERRORLOGOUTALL);

    }


    Mark123 Guest

  2. Similar Questions and Discussions

    1. #38325 [Ver->Csd]: spl_autoload_register() gaves wrong line for "class not found"
      ID: 38325 Updated by: iliaa@php.net Reported By: marcos dot neves at gmail dot com -Status: Verified +Status: ...
    2. how to get a file from the "Testing Server" / "remote view"
      if I want to get a particular file from the "Testing Sever" or "remote view" in my extension, how can i do so? Thanks a lot!!!
    3. #17495 [Com]: Failed opening .. (include_path=".") in Unknown on Line 0 OFTEN! (not always)
      ID: 17495 Comment by: heliumonline at optusnet dot com dot auNOSPAM Reported By: jhanna at qcora dot com Status: ...
    4. #9567 [Com]: Warning: file("http://www.php.net") - Bad file descriptor in /usr/........
      ID: 9567 Comment by: bojan dot kraut at birostroj dot com Reported By: christian dot goebel at sagra dot lu Status: ...
    5. How to make the "search text" feature work with non "txt" file
      On Fri, 27 Jun 2003 07:19:23 -0700, "Juergen" <anhorn@bktel.com> wrote: See MVP Doug Knox' comments and fix here:...
  3. #2

    Default Re: why "Bad file descriptor at line 94 "


    On Jan 26, 2004, at 3:03 PM, mark123 wrote:
    [..]
    >
    > This script telnets into a telnet server (cisco) then telnets into
    > other
    > cisco router to grab there configs. I get these errors when trying to
    > connect to certain routers (5, 11,12,13,14). If I look in my dump logs
    > I see
    > that the device didn't echo anything back. I have play with some
    > control and
    > break commnads wich help but doesn't fix all of them. I have a feeling
    > it
    > has something to so with the filehandle or buffer but not sure.
    >
    > Either case can anyone tell me why I am getting Bad file descriptor at
    > line
    > 94 ?? I have the line marked ****
    >
    > This is my first perl script so please don't laugh ;-(
    >
    [..]
    >
    > use Net::Telnet::Cisco;
    > $session = Net::Telnet::Cisco->new(
    > Host => $host,
    > Dump_Log => "c:/perl/bin/".$filename,
    > Input_log => "c:/perl/bin/".$file,
    > Timeout => $secs);
    [..]
    > use Net::Telnet::Cisco;
    > $session = Net::Telnet::Cisco->new(
    > Host => $host,
    > Port => $port,
    > Dump_Log => "c:/perl/bin/routerdump".$line.".txt",
    > Input_log => "c:/perl/bin/router".$line.".txt",
    > Timeout => $secs,
    > Errmode => sub {
    > #print "\n\n!!Bad command ? ". "port: $port!!!!! $! \n";
    > $error = $error + 1; # 1 means error has occurred.
    > warn $!;
    > # option are die return and warn ***THIS IS LINE 94 *************
    > }
    > );
    [..]


    First off, you will want to become good friends with

    a. 'use strict' and 'use warnings'
    b. only putting that
    use Foo::Bar
    once.

    The error around line 94 could be one of several problems.
    Those of course will be easier to identify once one has
    started to sort out which variables in the problem are
    not a part of the problem.

    I presume that you have read the POD for both
    Net::Telnet
    Net::Telnet::Cisco

    Your comment notes the options as 'die', 'return' and 'warn'
    and yet you are using a specific piece of there....


    You might want to try say

    sub my_cisco_err_handler {
    $error = $error + 1; # 1 means error has occurred.
    warn $!;
    }

    use Net::Telnet::Cisco;
    $session = Net::Telnet::Cisco->new(
    Host => $host,
    Port => $port,
    Dump_Log => "c:/perl/bin/routerdump".$line.".txt",
    Input_log => "c:/perl/bin/router".$line.".txt",
    Timeout => $secs,
    Errmode => \&my_cisco_err_handler
    );

    You might also find a better place to write your Dump_log
    and hence also where you are puttng your Input_log to read from
    and put those in variables as well...


    ciao
    drieux

    ---

    Drieux Guest

  4. #3

    Default Re: why "Bad file descriptor at line 94 "

    mark123 wrote:
    > Hi all,
    >
    > Can someone give me a hand understanding why I am getting this error.
    >
    > This script telnets into a telnet server (cisco) then telnets into other
    > cisco router to grab there configs. I get these errors when trying to
    > connect to certain routers (5, 11,12,13,14). If I look in my dump logs I see
    > that the device didn't echo anything back. I have play with some control and
    > break commnads wich help but doesn't fix all of them. I have a feeling it
    > has something to so with the filehandle or buffer but not sure.
    >
    > Either case can anyone tell me why I am getting Bad file descriptor at line
    > 94 ?? I have the line marked ****
    That is good. It helps a lot Please do this again when you re-post.
    >
    > This is my first perl script so please don't laugh ;-(
    >
    > This is ussing active state on an XP machine.
    > This is perl, v5.6.1 built for MSWin32-x86-multi-thread
    > (with 1 registered patch, see perl -V for more detail)
    >
    > thanks for any help
    Hi Mark,

    It doesn't look like you are getting much response here. Might I suggest soe
    factors that are making it more difficult to read the code, and thus to offer
    cogent advice?

    1. The code is too spread out to follow clearly. It is very difficult to
    understand or debug code when you need a telescope to see from one line to the
    next. I would recommend inserting a single blank line only when there is a
    shift in emphasis of the flow of execution. Such blanks lines should mean
    something.

    2. Likewise, the code is too spead out in the horizontal direction. I would
    suggest using auto-indent with spaces rather than tabs, and keeping the indents
    to four spaces maximum. I would also suggest doing a hard break when lines get
    longer than 80 characters. You simply cannot debug what you can not see.

    I know this probably sound anal-retentive, but I frankly cannot follow this
    code, and others may also pass it over for the same reason. By making some
    simple adaptations that help us understand this code, you may also help yourself
    considerably.

    Just make a common-sense visual evaluation, and change the things that make the
    code hard to follow. Then repost. There are many willing helpers here.

    Joseph


    R. Joseph Newton Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139