• May 22, 2012, 08:43:25 PM
Welcome, Guest. Please login or register. Registration is free.
Did you miss your activation email?

Author Topic: Perl Script SSH Session and Crtl+Y  (Read 557 times)

0 Members and 1 Guest are viewing this topic.

Offline hosh

  • Rookie
  • **
  • Posts: 9
Perl Script SSH Session and Crtl+Y
« on: August 19, 2011, 03:18:43 AM »
Hallo,

does anybody know how to connect to an ERS 4XXX 5XXX with a perl script by using SSH?


The Task is to change Passwords for Cli and snmpv3 phrases on a bundle of devices. There are a lot of scripts for Cisco with the Module Net::Appliance::Session. When i try a script with this modul ist works (ssh session opens username and password will be transmitted) but how do i get "ctrl+y" in the session, i think if i get a prompt everything is fine and i can use this script like on a cisco machine (i tested another script on some cisco machines).


Code: newbielink:javascript:void(0); [nonactive]
#!/usr/bin/perl
 use warnings;

 use Net::Appliance::Session;

 my $ios_device_ip = 'deviceIP';

 my $ios_username        = 'username';
 my $ios_password        = 'password';
 my $ios_enable_password = 'cisco';

 #my $running_config_file = "$ENV{HOME}/running_config.txt";

 my $session_obj = Net::Appliance::Session->new({
     personality => 'nortel',
     Host      => $ios_device_ip,
     Transport => 'SSH',
 });

 # give verbose output whilst we run this script
 $session_obj->input_log(*STDOUT);

 $session_obj->connect(
     Name => $ios_username,
     Password => $ios_password
 );
 sleep 1;
#Crtl+Y, but it will not work
 print $session_obj->cmd(String => '\cY');
 sleep 1;
 $session_obj->close;

cheers


Offline Flintstone

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 584
Re: Perl Script SSH Session and Crtl+Y
« Reply #1 on: August 19, 2011, 04:22:57 AM »
Hi Hosh,

I use Solarwinds and they use a form of scripting to do the same thing and I was involved in the developement of this script below.  Maybe this will point you in the right direction?

<Configuration-Management Device="Avaya Ethernet Routing Switch 5650TD" SystemOID="1.3.6.1.4.1.45.3.74.4">
   <Commands>
      <Command Name="RESET" Value="terminal length 0"/>
      <Command Name="Reboot" Value="reload"/>
      <Command Name="EnterConfigMode" Value="config terminal"/>
      <Command Name="ExitConfigMode" Value="end"/>
      <Command Name="Startup" Value="config"/>
      <Command Name="Running" Value="running-config"/>
      <Command Name="DownloadConfig" Value="show ${ConfigType}"/>
      <Command Name="UploadConfig" Value="${EnterConfigMode}${CRLF}${ConfigText}${CRLF}${ExitConfigMode}"/>
      <Command Name="DownloadConfigIndirect" Value="copy ${ConfigType} ${TransferProtocol} address ${StorageAddress} filename ${StorageFilename}${CRLF}"/>
      <Command Name="UploadConfigIndirect" Value="copy ${TransferProtocol} ${ConfigType} address ${StorageAddress} filename ${StorageFilename}${CRLF}"/>
      <Command Name="EraseConfig" Value=""/>
      <Command Name="SaveConfig" Value="write memory"/>
      <Command Name="Version" Value="show sys-info"/>
      <Command Name="PreCommand" Value="${CTRL+Y}"/>
      <Command Name="VirtualPrompt" Value="Main Menu"/>
      <Command Name="EnterCLI" Value="c" Delay="300" RegEx=""/>
      <Command Name="Menubased" Value="true"/>
   </Commands>
</Configuration-Management>


CheerZ and good luck