Menu

Automatically send a command after connection

Help
Steve
2012-08-21
2014-04-24
  • Steve

    Steve - 2012-08-21

    Hello, I was wondering if it were possible to automatically send a command to the server once a connection have been established.

    I thought this was what pre/post exec were for, but whatever I enter there it does not execute on the remote server.

    Is there a way to automatically send a command (ex: 'whoami') everytime a connection is established with a particular node?

     
  • David Torrejón Vaquerizas

    Hi!

    Yes, PAC was built with that in mind! ;)

    Simply edit your connection and goto to the "Expect" tab:

    - click "Add"
    - on "Expect", right click and choose <command prompt>
    - on "Send", write your command (leave the rest of fields with their default values)
    Save and try! :)

    - David.

     
  • Frank Markgraf

    Frank Markgraf - 2014-04-23

    For me the expect tab is grey. I installed the expect package, and can run the expect command from the command line. Anything else I have to enable?
    -- Frank

     
  • David Torrejón Vaquerizas

    Hmmm... what? THAT'S weird...

    What PAC version are you using?
    What type of connection are you experiencing those problems? (ssh, telnet, ...)

     
  • Frank Markgraf

    Frank Markgraf - 2014-04-24

    I'm on 4.5.4, and it is a ssh session.
    Can it be a permission problem such that pac does not see that expect is installed?

     
  • David Torrejón Vaquerizas

    No, PAC has nothing to do with "Expect" package (it uses it's own Perl expect bindings, which are automatically installed).

    Does that happen only on that connection, or on EVERY SSH connection??
    Really, this is the first time I see someone with this problem... :(

    • David.
     
  • Frank Markgraf

    Frank Markgraf - 2014-04-24

    Thanks for investigating. It does not work for any ssh connection, it is grey for all connections.

    And I just found the: I have enabled manual authentication. This makes the expect tab grey.

    It is kind of logical, but for me the 'manual' connection is established automatically. My ssh key is automatically sent on connection, don't know why. Thus my setup has manual authentication selected, but user 'root' specified under User/Password, although that option is not selected. I could not get it to work with any other combination.

    If you have a clue how I should configure the connection parameters otherwise, let me know.

    • Frank
     
  • Frank Markgraf

    Frank Markgraf - 2014-04-24

    The behaviour for the other connection options is like this:
    The connection to remote server is successfully established, and I can see the remote system's output and a command prompt. However, I cannot enter anything because PAC does not recognize the connection as established. The status indicator remains on 'Disconnected'.

    The only way it works for me is: Select user/password as authentication method, enter user 'root' there, then change the authentication to manual. The root value remains in the user/password section greyed out, but I will be authenticated successfully with my key which is sent by default.

    I understand that this disables the expect tab.

    • Frank
     

Log in to post a comment.