in reply to Control::CLI and Additional Prompt At Login

I figured out quite an easy fix for this a while after posting. Numerous rounds of testing have proven it out. I asked for the extra prompt to be changed from "ID:" to "ID>". This made my code think the login was all good. From there, I added code (through trial and error) to handle the extra prompt after the code block in my original message, like so:

$port = $cli->port; if ( defined($port) ) { print "\tSSH connection to server ($host) established!\n"; } else { print "\tSSH connection to server ($host) could not be established +... Exiting program.\n"; exit; } $output = $cli->cmd(""); $output = $cli->cmd("IJAF"); $output = $cli->cmd("clear"); $output = "";

Thanks as usual, Monks!!

Replies are listed 'Best First'.
Re^2: Control::CLI and Additional Prompt At Login
by lgas (Acolyte) on Sep 14, 2014 at 12:13 UTC

    Sorry I'm late, but better late than never!..

    The connect() method in Control::CLI only handles the connection, it does not try to lock onto a prompt; only login() and cmd() do that..

    So I think the original problem was that you were sending your first command while the *nix host was expecting the unique ID.

    So I would suggest a cleaner approach would be the following:

    $cli = new Control::CLI( Use => 'SSH', Timeout => 30, ); $cli->connect( Host => $host, Username => 'abc', Password => 'pass', ) or do { print "\tSSH connection to server ($host) could not b +e established\n"; exit; } $cli->login( Username => 'IJAF', Username_prompt => 'unique ID[:>]\s*$', ) or do { print "\tCould not get prompt from server ($host)\n"; exit; } print "\tSSH connection to server ($host) established!\n"; $output = $cli->cmd("clear"); ...

    The above login() method will now supply IJAF if it sees a prompt for the unique ID; once it sees a valid prompt (whether or not it got requested for the unique ID) it will return with a true value and you can then proceed to send the commands you need with cmd()..