easyrider has asked for the wisdom of the Perl Monks concerning the following question:

Hi PerlMonks I have a requirement thats need to be fulfilled using Perl. Requirement is as follows - 1) First, from Device A i need to connect to Device B using SSH/Telnet 2) After i successfully connect to Device B, i need to run a unique command (not using SSH/Telnet) and connect to Device C 3) After connecting to device C, i need to run few commands and capture some information. 4) later exit from device C 5) finally exit from device B and return back to device A Can anyone please suggest how to achieve this Thanks in advance!!!!!
  • Comment on Connection to devices and command execution

Replies are listed 'Best First'.
Re: Connection to devices and command execution
by MidLifeXis (Monsignor) on Feb 07, 2017 at 22:20 UTC

    Perhaps the Expect series of modules might be of use. There are also PTY handlers, and others that fall into the same problem space.

    --MidLifeXis

Re: Connection to devices and command execution
by davido (Cardinal) on Feb 08, 2017 at 03:19 UTC

    Even after reading your follow-up to this question I'm still unclear what you mean by "...After I successfully connect to Device B, i need to run a unique command (not using SSH/Telnet) and connect to Device C..."

    -----             -----            -----
    | A | <-> SSH <-> | B | <-> ?? <-> | C |
    -----             -----            -----
    

    So from A to B you have an SSH connection, will run some commands on B. For that you could use Net::SSH::Expect or Net::SSH2::Expect. Then B is supposed to execute some commands on C and gather information. What protocol will be spoken between those two boxes, if not telnet nor SSH? Is there a daemon set up on C listening to requests from B and responding?


    Dave

      Hi Dave Thanks for your reply. I will give the output received when i do it manually.

      sramaraj@inchetufmstg04 ~$ ssh -l gncstool -p 22 10.116.239.2
      Password:
      Last login: Wed Feb 8 10:32:52 2017 from 93.183.30.217 Sun Microsystems Inc. SunOS 5.10 Generic January 2005
      gncstool@seyuas1> eaw MSC01
      <

      inchetufmstg04 - Device A
      10.116.239.2(seyuas1) - Device B
      MSC01 - Device C
      to connect to Device c "eaw MSC01" is used. And once we are connected successfully, we get the Device c prompt which is "<"
      we execute the commands on Device c to fetch required information

Re: Connection to devices and command execution
by choroba (Cardinal) on Feb 07, 2017 at 16:08 UTC
    Hi easyrider,

    Welcome to the Monastery.

    What do you mean by to run a unique command (not using SSH/Telnet)?

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      hi to connect to Device c, ssh or telnet is not used. A command for example - "esx device01" is executed. On execution of this command we connect to "device01" and its respective prompt comes up