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

hi all,
this is the code segment
foreach my $cmd_telnet (@telnet_drop) { $telnet->print("$cmd_telnet"); (my $prematch, my $match) = $telnet->waitfor('/0 Successful/') or + print "notok\n"; print "$match\n"; if ( $match eq "0 Successful" ) { print OUT_succ "$cmd_telnet \t Successful\n"; } else { print OUT_fail "$cmd_telnet \t NOT OK\n" } }
so the problem.
when the match is not "0 Successful" it dies but it shoud not, i try with this or behind but didnt work either

when the match is not "0 Successful" it shoud go on and do the else i already try getline but getline returns me the command i just put on the machin with print $cmd_telnet

so have someone an idear or a solution ;D thx in advance The error message is Died pattern match timeout

Replies are listed 'Best First'.
Re: telnet waitfor problem
by timos (Beadle) on Mar 23, 2006 at 09:53 UTC
    Can you tell why it dies? What ist the error message?
Re: telnet waitfor problem
by laceytech (Pilgrim) on Mar 24, 2006 at 04:27 UTC
    I do not know the particulars of the telnet module you are using. You could change the logic of your return
    foreach my $cmd_telnet (@telnet_drop) { $telnet->print("$cmd_telnet"); if ($telnet->waitfor('/0 Successful/')){ print "$cmd_telnet \t Successful\n"; } else { print "$cmd_telnet \t NOT OK\n" } }
      i will try this tomorror because vpn is not working atm and let you know if it works or not.
      thx for the suggestion
      dosn't work
      returns the same error msg
      have no clue how i can get it to work
Re: telnet waitfor problem
by chargrill (Parson) on Apr 01, 2006 at 00:15 UTC

    Just out of idle curiousity, what happens when you perform the steps manually - in other words open your own telnet session to the target server, manually type in the commands you think you're sending via your perl script - do you see the telnet session return text matching "0 Successful"? (Apologies if I'm missing something, as I'm not familiar with Net::Telnet)

    Update: I found out I have Net::Telnet installed on my local system, so a quick perusal of the docs shows:

    Debugging The typical usage bug causes a time-out error because you've ma +de incorrect assumptions about what the remote side actually sends +. The easiest way to reconcile what the remote side sends with your e +xpecta- tions is to use "input_log()" or "dump_log()". "dump_log()" allows you to see the data being sent from the rem +ote side before any translation is done, while "input_log()" shows you t +he results after translation. The translation includes converting + end of line characters, removing and responding to TELNET protocol com +mands in the data stream.

    Maybe $telnet->dump_log() will help you out.

    $,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}
      0 Succsessfull means the command wents trough and its processed right any other return is a failure for exp 1999 Succesfull or because its an crapy damn old laggy total ... machin it just spit out some prov bla foobar text when i do it manuall mostly 0 Successful apears but somtimes 1999 or somthing else so the script basicly is working just the errormode is wrong as i get in the chatbox ;D default is DIE
      my $telnet = Net::Telnet->new(Timeout => 30,Errmode => 'return'); solves the problem but thx to all of you for help