On 8 Jun 2004 04:51:44 -0700,
gullia@visir.is (G520) wrote:
[color=blue]
>Hi
>
>I have been getting statistical rapports from a machine via a
>telnet server. Until now it has been done manually. However
>I want to automate the proccess, and scedule a PHP script to
>run everyday.
>
>Using my terminal, I give the command to order a rapport,
>and then press <ESC>. Then the rapport is printed out.
>
>Using a PHP script I can order a rapport, all works fine,
>except I can not get the printout. When I try to send <ESC>
>the telnet server responds with "syntax fault" so
>I'm not doing it right.
>
>I have tried the following:
>
>$do_esc=chr(27);
>fputs ($fp, "$do_esc");
>
>and
>
>fputs ($fp, "\e");
>
>Any ideas???
>
>
>
><?php
>$address = '100.100.1.5024';
>$port = 5000;
>$fp = fsockopen($address,$port);
>$s='o';
>$s=fgets($fp,128); //the telnet server responds when connected
>echo("<br>$s<br>");
>
>fputs ($fp, "SOME-COMMAND"); //some command to order a rapport
>$s=fgets($fp,128);
>echo("<br>$s<br>"); //telnet server responds with "rapport failed" or "executed"
>
>/*
>Here the tricky part starts,
>trying to get the rapport
>printed out. No success so far.
>To get the rapport printed out
><ESC> has to sent to the telnet
>server
>*/
>
>$do_esc=chr(27);
>fputs ($fp, "$do_esc"); //this does not work, trying to
> //send <ESC> to the telnet server.
>
>while (!strstr($t,'END')) { // supposed to get the printout
> $t=fgets ($fp,128); // that never comes
> echo("<br>$t");
> }
>fclose($fp);
>?>[/color]
define('ESCAPE', 0x1B);
fputs($fp, ESCAPE . "\n"); // probably needs the \n for the recieving end to process the data.
fflush($fp); // make sure the data is sent to the recieving end now...