I need to write a script to telnet or ssh a device the execute some commands in device then copy the output in a file, I wrote the script but I faced one issue, when you execute some commands the device asked me a Question, for example :
device # copy run tftp
device # Source filename [running-config]?
then the script hang, my Question is how to pass the answers to device using perl ??
Thanks a lot for your reply
May you please explain me more with examples,
This is my telnet script :
#!/usr/local/bin/perl
$ip = $ARGV[0];
die ("IP must be passed as an argument. $!\n") unless defined($ip);
use Net::Telnet ();
$handle = new Net::Telnet (Timeout => 10, Prompt => '/.*(#|>|\))\s*$/');
$handle->open("$ip");
$handle->login("Username","password");
$handle->cmd("terminal length 0");
@lines = $handle->cmd(" ANY COMMAND HERE NEED ANSWER");
print "@lines";
$handle->cmd(exit);
$handle->close;