RedTussock has asked for the wisdom of the Perl Monks concerning the following question:
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.
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 #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
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 ...#!/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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Sniffing a telnet session into a file ...
by zentara (Archbishop) on Oct 07, 2012 at 11:24 UTC | |
Re: Sniffing a telnet session into a file ...
by aitap (Curate) on Oct 07, 2012 at 13:24 UTC | |
by RedTussock (Acolyte) on Oct 07, 2012 at 17:21 UTC | |
Re: Sniffing a telnet session into a file ...
by NetWallah (Canon) on Oct 07, 2012 at 15:37 UTC | |
by RedTussock (Acolyte) on Oct 07, 2012 at 17:29 UTC | |
by NetWallah (Canon) on Oct 07, 2012 at 20:24 UTC | |
Re: Sniffing a telnet session into a file ...
by zentara (Archbishop) on Oct 08, 2012 at 11:03 UTC | |
by RedTussock (Acolyte) on Oct 11, 2012 at 05:40 UTC | |
by zentara (Archbishop) on Oct 11, 2012 at 12:04 UTC |
Back to
Seekers of Perl Wisdom