I had requirement to send command to remote device and whenever it ask for “Press CTRL+C to break, other key to continue…” I should again send “Enter key” to remote device.
I have written below scritpt but somehow it doesn’t work.
my $session = new Net::Telnet (
Timeout => 30,
Prompt=> '/>/',
Input_log =>\*STDOUT
);
$session->open('device-id');
$session->login('admin','admin');
print "connected and logged in \n\n";
print "Kindly wait till output stored in FILE \n\n";
my @output1=$session->cmd('DSP PATCH:;');
if ($session->waitfor('/Press CTRL+C to break, other key to continue.../')) {
$session->print(''); # Assuming default is \n for print command
}
print @output1;
Output of above script is
connected and logged in
Kindly wait till output stored in FILE
.
.
some output of command send...........
.
Press CTRL+C to break, other key to continue...
and then it timeout.
Any idea how to send enter hit till my remote device ask me to hit enter.
The
cmdmethod sends a command and waits for the prompt. Instead, either run your command usingprintandwaitfor(most likely saving the returned prematch), or override the prompt for thatcmdcall with the remote message. I’d suggest doing the former.