I'm using script to grab following comma separated data from telnet port. (x86, Windows, ActivePerl) There is coming quite a lot of data from port. several lines per second producing hudreds kilobytes logfile in small time.
Link to example rawdata which is coming out from telnet port:
http://oh2gax.dyndns.org/~ode/kamaa/logfile_raw.txt
The script grabs only that lines which started with MSG,3 split the data and takes needed columns from it. Then it reproduces date stamped file with following format:
3C5122,60.34987,25.01473,1050,14:50:36.275
461F35,60.45609,25.17939,3575,14:50:36.275
3C6663,59.48836,21.67773,33025,14:50:36.275
The functionality what I want:
I need to grab the additional data from message line MSG,4. Normally these lines are pairs, MSG,4 line after the MSG,3, but sometimes there are only MSG,3 followed by MSG,8 or any other. I want grab now also additional columns from MSG,4 line which immediately after MSG,3 and only then when data on fifth column (look raw_data) (etc. 462F95) is same in both lines.
MSG,3,7,5439,462F95,......
MSG,4,7,5439,462F95,......
Producing data line for example:
462F95,60.45609,25.17939,3575,428.2,217.2,14:50:36 .275
If, column 5 in MSG,4 line doesn't match with MSG,3 or line is totally different, only MSG,3 line is taken and additional column data is replaced in that case with values 0.0,0.0.
etc.
462F95,60.45609,25.17939,3575,0.0,0.0,14:50:36.275
I'am very new with Perl, and would be very glad if someone could give help to create code with above functionality. Do I have to do some data buffering or make temporaly files?
----
Expand|Select|Wrap|Line Numbers
- #!/perl
- use Net::Telnet;
- my $host = "hostname";
- my $user = "";
- my $password = "";
- my $prompt = "";
- my (@data, $line);
- my $t = new Net::Telnet(Timeout=> '5', port => '23');
- $t->errmode('return');
- $t->Net::Telnet::open($host);
- sleep 5;
- while (<$t>)
- {
- if (m/MSG,3/)
- {
- #print;
- @data = split(/,/);
- ($day, $month, $year) = (localtime)[3, 4, 5];
- $year += 1900;
- $month++;
- $date = sprintf '%02u%02u%02u', $day, $month, $year;
- #print $date;
- open LOGFILE, ">>$date.txt" or die "Can't open file";
- print LOGFILE $data[4].",".$data[14].",".$data[15].",".$data[11].",".$data[7]."\n";
- print $data[4]." ".$data[14]." ".$data[15]." ".$data[11]." ".$data[7]."\n";
- }
- }
- $t->close();
laxlou