#!/usr/bin/perl use strict; use Net::Telnet; my ($host, $station_id) = @ARGV; my $telnet = new Net::Telnet; $telnet->open(Host => $host, Port => 12345, Timeout => 60); $telnet->waitfor('/Bad/'); $telnet->waitfor('/Bad/'); my ($retval_prematch, $retval_match) = $telnet->waitfor(Match => '/Login user:/', Match => '/Flash Disk>/'); print "retval_match:".$retval_match."\n"; if ($retval_match eq 'Flash Disk>') { $telnet->print("exit"); $telnet->waitfor('/Login user:/'); } #$telnet->waitfor('/Login user:.*$/'); $telnet->print("p"); $telnet->waitfor('/Password:/'); $telnet->print(""); =pod $telnet->waitfor('/Login user:/'); $telnet->print("p"); $telnet->waitfor('/Password:/'); $telnet->print(""); $telnet->waitfor('/Login user:/'); $telnet->print("p"); $telnet->waitfor('/Password:/'); $telnet->print(""); =cut my $line; my @line_array; $telnet->getline; #blank line $line = $telnet->getline; print $line; @line_array = split(/\s+/, $line); my $date = @line_array[2]; my $time = @line_array[3]; my $line = $telnet->getline; print $line; @line_array = split(/\s+/, $line); my $water_level = @line_array[2]; if ($station_id ne '8668498') { #Fripp is an oddball in feet $water_level = sprintf("%.3f", $water_level/3.28); } my $sigma = @line_array[3]; $line = $telnet->getline; print $line; @line_array = split(/\s+/, $line); my $wind_speed = @line_array[2]; my $wind_direction = @line_array[3]; my $wind_gust = @line_array[4]; $line = $telnet->getline; print $line; @line_array = split(/\s+/, $line); my $air_temperature = @line_array[2]; $line = $telnet->getline; print $line; @line_array = split(/\s+/, $line); my $air_pressure = @line_array[2]; print "parsed\n"; my $datetime = $date." ".$time; print "datetime:".$datetime."\n"; print "water_level:".$water_level."\n"; print "wind_speed:".$wind_speed."\n"; print "wind_direction:".$wind_direction."\n"; print "wind_gust:".$wind_gust."\n"; print "air_temperature:".$air_temperature."\n"; print "air_pressure:".$air_pressure."\n"; open(WLS_TMP, ">./wls.sql"); print WLS_TMP "INSERT INTO water_level (row_id,station,d,se,wl,sigma,o,f,r,t,l,entry_date,datetime) VALUES (nextval('water_level_seq'),$station_id,1,'A1',$water_level,$sigma,0,0,0,0,0,now(),'$datetime');\n"; print WLS_TMP "INSERT INTO wind (row_id,station,d,se,ws,wd,wg,x,r,entry_date,datetime) VALUES (nextval('wind_seq'),$station_id,1,'C1',$wind_speed,$wind_direction,$wind_gust,0,0,now(),'$datetime');\n"; print WLS_TMP "INSERT INTO air_temperature (row_id,station,d,se,at,x,n,r,entry_date,datetime) VALUES (nextval('air_temperature_seq'),$station_id,1,'D1',$air_temperature,0,0,0,now(),'$datetime');\n"; print WLS_TMP "INSERT INTO barometric_pressure (row_id,station,d,se,bp,x,n,r,entry_date,datetime) VALUES (nextval('barometric_pressure_seq'),$station_id,1,'F1',$air_pressure,0,0,0,now(),'$datetime');\n"; close (WLS_TMP); `/usr/local/pgsql/bin/psql -U postgres -d wls -f wls.sql`; exit 0;