473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Telnet data logging, comma separated data

2
Hi,

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
  1. #!/perl 
  2. use Net::Telnet; 
  3. my $host = "hostname"; 
  4. my $user = ""; 
  5. my $password = ""; 
  6. my $prompt = ""; 
  7. my (@data, $line); 
  8. my $t = new Net::Telnet(Timeout=> '5', port => '23'); 
  9. $t->errmode('return'); 
  10. $t->Net::Telnet::open($host); 
  11. sleep 5; 
  12. while (<$t>) 
  13. if (m/MSG,3/) 
  14. #print; 
  15. @data = split(/,/); 
  16.  
  17. ($day, $month, $year) = (localtime)[3, 4, 5];
  18. $year += 1900;
  19. $month++;
  20. $date = sprintf '%02u%02u%02u', $day, $month, $year;
  21. #print $date;
  22.  
  23. open LOGFILE, ">>$date.txt" or die "Can't open file";
  24. print LOGFILE $data[4].",".$data[14].",".$data[15].",".$data[11].",".$data[7]."\n";
  25. print $data[4]." ".$data[14]." ".$data[15]." ".$data[11]." ".$data[7]."\n"; 
  26. $t->close();
  27.  
  28.  

laxlou
Nov 23 '06 #1
1 2833
laxlou
2
Problem solved, no help needed anymore. :-)


---
laxlou
Nov 27 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Craig Keightley | last post by:
is it possible to compare acomma separated list aginst another eg comma list 1 => 1,2,3,4,5 comma list 2 => 3,5 can you check that 3 is in both, and 5 is in both, therfore they match??? the...
2
by: john brown | last post by:
I'm telnetting into a router. Apart from the fact I can't seem to view the output when iniciating the session, I can't match one of the expressions using Net::Telnet. I can telnet into the router...
5
by: Michael Hill | last post by:
Hi, folks. I am writing a Javascript program that accepts (x, y) data pairs from a text box and then analyzes that data in various ways. This is my first time using text area boxes; in the past,...
2
by: pesso | last post by:
I have a string that contains the following: string s = "130,41,43,178,41,17,6,78,244,35,202,144,115"; They are comma separated byte numbers, and I need to initialize my byte array with them....
1
by: bneron | last post by:
hello, I use the logging module include in Python 2.4 distribution, and I 'd like to have a logger witth several Handlers . I know how to do this by coding in python, but could I specify this...
17
by: mac | last post by:
Hi, I'm trying to write a fibonacci recursive function that will return the fibonacci string separated by comma. The problem sounds like this: ------------- Write a recursive function that...
13
by: mac | last post by:
Hi, I'm trying to write a fibonacci recursive function that will return the fibonacci string separated by comma. The problem sounds like this: ------------- Write a recursive function that...
4
by: sufian | last post by:
Below is the field where user enters his/her email address and the AJAX post request is sent to the server and the user sees the message: echo("<div id=\"message\" class=\"success\">Thank you! You...
17
by: ravimath | last post by:
Dear all, I have written following script to loin to router bu it is showing error. #!c:\Perl\bin; use strict; use warnings; my $hostname = 'REMOVED FOR YOUR PROTECTION'; my $password =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.