Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I operate a home made 1 wire weather station which I monitor using a very good app called OWW. OWW sends a txt line of data out on port 8891 on the localhost which can be read by telnet 'ing the localhost on that port. What I would love to do is establish a telnet session, take the 1 line result and write it to a file and eventually upload onto the net .. Has anyone here had a go at something like this .. below is the code I am working on ... and code I use to grab data from the MySQL server which OWW keeps fed as well.
#!/usr/bin/perl -w #Telnet Script to read the OWW tcp port and write the output to a file + for upload to the net # # use Net::Telnet (); use Cwd; open my $fh, '>', '/home/Smitty/scripts/perl/WLStickers.txt' or die $! +; { $t = new Net::Telnet (Timeout => 10, Output_log => $ofile); $t->open("127.0.0.1 8891"); $t->close; } exit 0
I acknowledge this is not working ... just not perl savvy enough to get it to go easily ... maybe the pixies will fix it overnite :-) Following is a script which was working uploading the required file, in the format requested by a local weather net group.
#!/usr/bin/perl -w use Net::FTP; use DBI; $dbh = DBI->connect('dbi:mysql:database','user','pass') or die "Connection Error: $DBI::errstr\n"; $sql = "select concat_ws(',' , TIME_FORMAT(NZST,'%h:%i') ,DATE_FORMA +T(NZST,'%d/%m/%y'),t2,'',wdchill,rh,dp,bp,'',wdspd,ROUND(wddeg),rn,'' +,'','','',wdgst,'c|kmh|mb|mm') FROM tbl_owwdata ORDER BY wx_idx DESC +LIMIT 1"; $sth = $dbh->prepare($sql); $sth->execute or die "SQL Error: $DBI::errstr\n"; while (@row = $sth->fetchrow_array) { open (MYFILE, '>WL_stickertags.txt'); print MYFILE "@row\n"; close (MYFILE); } $ftp = Net::FTP->new("some.where.com", Debug => 0) or die "Cannot connect to Simplehost: $@"; $ftp->login("******",'*******') or die "Cannot login ", $ftp->message; $ftp->cwd("/a.b.c/folder") or die "Cannot change working directory ", $ftp->message; $ftp->put("WL_stickertags.txt") or die "put failed ", $ftp->message; $ftp->quit; exit 0
Of course it would be much more fun to snif the 1 wire net directly and format a web page with results and graphs etc. But small steps grasshopper ...

In reply to Sniffing a telnet session into a file ... by RedTussock

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (8)
    As of 2014-11-29 07:38 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (204 votes), past polls