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

Hi All,

I am trying to reboot a system by telnet into it. While executing the reboot command , the system is asking this question "This operation will reboot ! Do you want to continue? (y/n)", now I have to issue the letter "y" through the perl telnet module, how do I do it ?

Here is what I tried but did not help
use Net::Telnet; my $telnetAC = new Net::Telnet( Timeout => 30,Port => $ACtelnetport ) +or die "connect failed: $!"; line21: $telnetAC->cmd("exe reboot"); $telnetAC->waitfor('/(y/n)/i'); $telnetAC->print("y");
command timed-out at C:\Learn_perl\xcheck_sta.pl line 21
Please help

Replies are listed 'Best First'.
Re: telnet module
by runrig (Abbot) on Aug 27, 2013 at 23:53 UTC
    Try adding a linefeed:
    $telnetAC->print("y\n");
Re: telnet module
by roboticus (Chancellor) on Aug 28, 2013 at 00:00 UTC

    ace_ravi:

    You might also want to check the options available on your reboot command. Some may offer a switch to allow you to reboot without the confirmation.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: telnet module
by DanielSpaniel (Scribe) on Aug 28, 2013 at 04:20 UTC

    I think I would be looking at trying to get the "yes" command to work with it.

    The "yes" command simply answers yes to any y/n prompts without the need for any user interaction.

    For example: # yes | rm -i *.txt

    The yes command here will answer yes to each file it prompts for a confirmation to delete.

    So, if you're able to pass in a command like "yes | reboot" then that may well work for you.

    Also see http://www.computerhope.com/unix/yes.htm

Re: telnet module
by jellisii2 (Hermit) on Aug 28, 2013 at 13:26 UTC
    Check out Control::CLI. It makes this kind of stuff a little easier.