#!/usr/local/bin/perl use LWP::Simple; # #---------------------------------------------------------- # ID/TRH autologging program # Pinnacle Technology, Inc. # 619 E 8th St. Suite D # Lwarence, KS 66044 # (785) 832-8866 # www.pinnaclet.com # # Installation: #Change the IP address to match that of the ID/TRH that you want to monitor, #select a log file name, make sure the perl path is correct, change the name of # this file to yourName.pl and schedule the perl script to run at a specific time #(Cron). For example, with 5 minute sampling, 500 minutes of data are always #available from the web page, so if the program is scheduled to run once every #6-8 hours, no data will be lost. The program automatically eliminates any #overlapping data. Feel free to modify or improve this program and contact #us with suggestions. This script requires perl and the libwww-perl library. #Perl is also free. All of the necessary modules can be found in the #ActivePerl download from Active State. For windows users this is the #best place to start. The log file created by the perl script is tab delimited; #a form which is compatible with most spreadsheets. # # Enter the URL for the ID and the log file name here # $log_file = "/home/djohnson/ezlog.txt"; $ez_url = 'http://24.124.24.93/log.txt'; # # get the data from the ID $new_data = get("$ez_url"); # # sort the data @data = reverse(split(/\n/, $new_data)); # # remove the header $header = pop(@data); $header =~ tr/A-Z,a-z,0-9,\t,\:,\///cd; # # see if this is the first time the log has been written $first=0; if(!(-e $log_file)) { open(OUT, ">$log_file") or die "Could not open log file\n"; print OUT "$header \n"; close OUT; $first=1; } # $ts1 = 0; # # if this is not the first time through find the last timestamp logged if(!$first) { # # open the log file and find the last entry # there has to be a better way to do this - open(IN, "<$log_file") or die "Could not open log file\n"; while(1) { $last_line = $line; $line = ; if(length($line) < 10) {last} } #print "line = $last_line\n"; close(IN); # # Find the last timestamp stored $last_line =~ tr/A-Z,a-z,0-9,\-,\t,\:,\///cd; ($ts1, $restofline) = split(/\t/, $last_line, 2); } # # write out the new data open(OUT, ">>$log_file") or die "Could not open log file\n"; while($line = shift(@data)) { $line =~ tr/A-Z,a-z,0-9,\-,\t,\:,\///cd; $line1 = $line; ($timestamp, $restofline) = split(/\t/, $line1, 2); if($timestamp > $ts1) { print OUT "$line\n"; } } close OUT; exit();