Posted on 2008-01-25 22:18:24-08 by chicks1dig1unix
How to send a carriage return?
When I use this module to log into the router and issue a command, it needs a confirmation to actually run the command, so I need the script to send a carriage return. I have tried to use cmd() function with a space as an argument, no arguments, and also the print('\r) function. It gives a timeout error, and when I connect to the console I see that it doesnt complete the command. How do I send a return using this module? Here is the code that I have now below:
eval { $session_obj->cmd('issu runversion 2 slavebootflash:cat4500e-entservicesk9-mz.122_44_SG_249.alpha') +; $session_obj->cmd(); $session_obj->print('/n'); print $session_obj->last_prompt; }; if ($@) { print "The error is: $@ \n\n"; }; sleep 10;
This is the error it gives: The error is: Timeout, EOF or other failure waiting for command response at issu_test line 36
Direct Responses: 6954 | Write a response
Posted on 2008-01-28 16:28:41-08 by oliver in response to 6937
Re: How to send a carriage return?
Hi chicks1dig1unix,

Okay, there is a trick to this, and I think after your good question I'll make a note in the docs of the next release of the module.

If you have a command which needs a confirmation (e.g. reboot) or something which asks a supplementary question then you need to provide a one-off custom match prompt to cmd() to override the built in standard prompt. Here's a couple of examples:

$s->cmd( String => "copy tftp://1.2.3.4/configs/hostconfig startup-config", Match => ['/Destination filename/'], ); $s->cmd("\n"); $s->cmd( String => 'reload', Match => ['/Proceed with reload/'], ); $s->cmd( String => "\n", Match => ['//'], );

Hope that helps!

regards,
oliver.
Direct Responses: 6957 | Write a response
Posted on 2008-01-28 20:38:49-08 by chicks1dig1unix in response to 6954
Re: How to send a carriage return?
Hi, thanks for your reply.. I tried this for my prompt, which is : This command will reload the Active unit. Proceed ? [confirm] Even after escaping the dot and brackets, it didnt work.. so I put the whole string into $prompt and did a
( string=("/n", Match=>[/$prompt/],);
It should interpolate the variable since its just a matching statement - This didnt do it either So last effort was to feed the output of the previous command to the $prompt variable ( which would just be the next prompt) and match that. And the string I used was still "/n". Still doesnt appear to read it Do you see if I am doing something wrong?
Direct Responses: 6959 | Write a response
Posted on 2008-01-28 20:45:54-08 by oliver in response to 6957
Re: How to send a carriage return?
Hi,

No I can't see exactly if there is anything wrong, although I don't know which command you are trying to run. From your previous post and latest post, my best guess would be for you to do something like this:

$s->cmd( String => 'issu runversion 2 slavebootflash:cat4500e-entservicesk9-mz.122_44_SG_249.alpha', Match => ['/Proceed/'], ); $s->cmd( String => "\n", Match => ['//'], );

I think you need two stages because the reload might never return a prompt, so the // lets the module accept that. In my experience it's also easier to match on just a part of the response e.g. "Proceed" rather than the whole line, because it's more reliable. Your mileage may vary, I guess.

Let me know how you get on,

regards,
oliver.
Direct Responses: 6961 | Write a response
Posted on 2008-01-28 23:03:33-08 by chicks1dig1unix in response to 6959
Re: How to send a carriage return?
Yes! It works. Thanks so much for your help
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.