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

Hello Monks. I am making a connection to a remote NE with Control::CLI. When I connect manually to the machine I eventually get to:

running OS installation script /bin/installgolddisk: version 2013-10-22.01 Enter local time as MMDDhhmmYYYY


I provide the required time stamp and all is good. When I connect through script, I see this:

©[34;47m/bin/installgolddisk: version 7-2015-12-14.01©[0m ©[34;47mEnter local time as MMDDhhmmYYYY©[0m


The garbage characters are messing up my script. Relevant code:

sub ConnectTo { my $ip = $_[0]; my $user = $_[1]; my $pass = $_[2]; my $obj = new Control::CLI ( Use => 'SSH', Timeout => 10800, Input_log => "$logprefix.input.log", Output_log => "$logprefix.output.log" +, Dump_log => "$logprefix.dump.log", Prompt => '.*[^boot:][m\?\$%#>:\r\n\ +012]\s?$', ); my $ok = $obj->connect( Host => $ip, Username => $user, Password = +> $pass, ); my $ok = $obj->login( Password => $pass,); return $obj; } $MRV_obj = &ConnectTo($MRVIP, $MRVUser, $MRVPass); $MRV_output = $MRV_obj->cmd("poweron server 1 usb\n\n"); my $Blade1Conn = $MRV_obj->cmd("connect server serial 1\n"); my $installprompttime = strftime ('%m%d%H%M%Y', gmtime); $MRV_output = $MRV_obj->cmd("$installprompttime");


So I'm guessing my prompt string isn't picking up the prompt with the garbage characters coming through. Any thoughts on removing the garbage, or altering my prompt to pick it up?

Thanks in advance!

Replies are listed 'Best First'.
Re: Control::CLI, SSH, Garbage Characters, & Prompt
by huck (Prior) on Feb 27, 2017 at 23:00 UTC

    if you take the copyright symbol as esc those look like vt100 terminal control sequences.
    http://www.termsys.demon.co.uk/vtansi.htm
    "Set Attribute Mode <ESC>[{attr1};...;{attrn}m"

    http://search.cpan.org/~lstevens/Control-CLI-2.03/lib/Control/CLI.pm
    "By default no terminal type is defined which results in TELNET simply not negotiating any terminal type while SSH will default to 'vt100'. Once a terminal type is set via this method, both TELNET and SSH will negotiate that terminal type. Use an empty string to undefine the terminal type."

    $obj = new Control::CLI ( <br>... <br>[Terminal_type => $string,] <br>... );

    try Terminal_type           => '', in the connect new Control::CLI

Re: Control::CLI, SSH, Garbage Characters, & Prompt
by ImJustAFriend (Scribe) on Mar 01, 2017 at 13:15 UTC
    Good morning Monks! I got this squared away by using waitfor (which I'd never been able to get to work prior) like so:

    $MRV_match = $MRV_obj->waitfor('MMDDhhmmYYYY.*\n'); my $installprompttime = strftime ('%m%d%H%M%Y', gmtime); $MRV_output = $MRV_obj->print("$installprompttime\ny");
Re: Control::CLI, SSH, Garbage Characters, & Prompt
by nysus (Parson) on Feb 27, 2017 at 22:49 UTC

    I don't know the answer to this problem but I see you are using ssh. I have been using Net::OpenSSH without a problem. Maybe it will be suitable alternative for your needs if you don't need access to lower level settings.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks