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

Hi,

I'm writing Perl program that running on Windows and should connect to UNIX via Telnet module. The telnet command should to execute tuxedo command on Unix side as describe below:

$telnet->cmd("/opt/bea/tuxedo8.1/bin/tmloadcf GPPconfig.ubb");
my question is how can I interactive with the tuxedo command, means to send an answer as describe below:
/opt/bea/tuxedo8.1/bin/tmloadcf GPPconfig.ubb Really overwrite TUXCONFIG file: /users2/t +ec3/fundtech/env/GPPconfig [y, q] ?
Please advice how can i send/approve the question , or enable the user to answer the question online. below is the part of my program that handling the telnet issues:
# Connect --------------------------- print "Connecting to $hostname($username:$password)...\n"; $telnet = Net::Telnet->new( Timeout => $timeout, Prompt => '/[\$%#>] $/' , Host => $hostname ); $telnet_put = Net::Telnet->new( Timeout => $timeout, Prompt => '/[\$%#>] $/' , Host => $hostname ); $telnet->login($username, $password); print "Login successfully.\n"; @results = $telnet->cmd("cd $envPath"); $telnet->cmd("/opt/bea/tuxedo8.1/bin/tmloadcfGPPconfig.ubb");
Thanks,
Yona

Replies are listed 'Best First'.
Re: Interactive input via telnet
by thezip (Vicar) on Nov 04, 2007 at 17:21 UTC

    Hello Noame, and welcome to PerlMonks!

    You might have noticed that you have received a couple of downvotes for your posting. This is probably due to the lack of formatting (which makes your node quite unreadable).

    Check out this node : Writeup Formatting Tips, and then update your node with the requisite <code></code> tags. Updating of nodes is OK, but it is also polite if you annotate the fact that you have done so.


    Where do you want *them* to go today?
Re: Interactive input via telnet
by KurtSchwind (Chaplain) on Nov 04, 2007 at 23:17 UTC
    If the goal is to answer in the affirmative for any prompt, try this instead.
    $telnet->cmd("echo y | /opt/bea/tuxedo8.1/bin/tmloadcf GPPconfig.ubb +");

    In Unix, those responses are expected in STDIN, so you can pre-answer those questions by usually just piping a response into a pipe. I don't have tuxedo so I didn't try this, but I'm fairly certain it'll work for you.

    Hope this helps.
    --
    I used to drive a Heisenbergmobile, but everyone I looked at the speedometer, I got lost.
Re: Interactive input via telnet
by regexes (Hermit) on Nov 05, 2007 at 13:17 UTC
    Hello,

    Take a look at the Net::Telnet documentation for the modules waitfor() and print().

    From the documentation:
    Consider using a combination of "print()" and "waitfor()" as an alternative to this method when it doesn't do what you want, e.g. the command you send prompts for input.
    Hope it helps!

    regexes


    -------------------------
    Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan "press on" has solved and always will solve the problems of the human race.
    -- Calvin Coolidge, 30th President of the USA.
Re: Interactive input via telnet
by glide (Pilgrim) on Nov 05, 2007 at 10:25 UTC
    You can try something like this:
    $telnet->print("/opt/bea/tuxedo8.1/bin/tmloadcfGPPconfig.ubb"); my ($prematch,$match) = $telnet->waitfor( -match => $telnet->prompt, # to wait for the + regular prompt -match => qr{\[y,\s*q\]}, # wait for the [y +, q] prompt ); $telnet->cmd("y") if ($match =~ qr{\[y,\s*q\]} );
      First, thanks for your quick answer. I got the following error in your code:
      missing opening delimiter of match operator in argument "(?-xism:/\[y, +\s*q\]/)" given to Net::Telnet::waitfor() at C:\Documents and Settings\yonae\wor +kspace\Dat abase_Connection\try.pl line 32
      Can you please advice. moreover, in this case I "know" for which question to wait for and sent the answer "y"... But, How can I write interactive code according to the input that I'll get? mean to present to the user the question and according to him choice to send the answer. Thanks.
        O can use a more generic match (like: /\s\?\s*$/) and then use the $prematch var to question the user about the prompt.