Loading ...
Sorry, an error occurred while loading the content.

Net:: Telnet question

Expand Messages
  • Dukelow, Don
    I m trying to figure out how to use Net::Telnet and I can telnet into other systems. But my problem is when I try to sudo to root to execute the commands I
    Message 1 of 3 , Jun 29, 2007
    • 0 Attachment
      I'm trying to figure out how to use Net::Telnet and I can telnet into
      other systems. But my problem is when I try to sudo to root to execute
      the commands I need to do. Anyway I get the error "esize: unknown
      character, exiting". I'm telneting between HP and Sun systems, but I
      can't quit get the process to work. Here is my code so fare and yes I
      know it is crude but any help would be great. Plus I can't seem to get
      the uname command to execute at the proper time if at all.

      sub run_TelnetCMD {
      my ($host, $OUT_PUT_FILE) = @_;

      my @user = split(/\./, $host);
      my $prompt = "$user[0] $LOGIN";

      my $TELNET = Net::Telnet->new( Timeout => 5,
      Prompt => "/$prompt/",
      Errmode => 'return',
      Host => "$host",
      Input_log => 'input',
      #Output_log => 'output'
      );
      $TELNET->login($LOGIN, $PASSWD);
      my $mesg = $TELNET->errmsg;
      if ((length $mesg) > 1) {
      $TELNET->close;
      print "ERROR: 1 $host $mesg\n";
      return;
      }
      $TELNET->cmd('sudo su -');
      $TELNET->waitfor('/Password/');
      $TELNET->print("$PASSWD");

      $TELNET->waitfor();

      $mesg = $TELNET->errmsg;
      if ((length $mesg) > 1) {
      print "ERROR: 2 $host $mesg\n";
      }

      &Telnet_server($TELNET, $OUT_PUT);
      }

      ####
      sub Telnet_server {
      my ($TELNET, $OUT_PUT) = @_;
      my $nic;

      open (OUT, ">$OUT_PUT") or die("ERROR $0 Telnet_server can't open
      $OUT_PUT $!");
      my @VENDER = $TELNET->cmd('uname -a');
      print OUT "@VENDER\n";

      close OUT;
      $TELNET->close;
      }
      -----
      Don Dukelow
      HP UNIX OVO Enrollment
      Hewlett-Packard Company
      e-mail: dukelow@...
      URL: http://www.hp.ca
    • Jim Swanson
      Message 2 of 3 , Jun 30, 2007
      • 0 Attachment
      • Jim Swanson
        Sorry about the blank message. Clicked the wrong link! jrs
        Message 3 of 3 , Jun 30, 2007
        • 0 Attachment
          Sorry about the blank message. Clicked the wrong link!

          jrs
        Your message has been successfully submitted and would be delivered to recipients shortly.