This is an old revision of the document!
To seperate data to daily files I use 3 scripts which will be executed via cronjobs.
This will execute socat with daily modified parameters. The logfile parameter will have the date of “today”. It starts at 12:02 am everyday.
#!/bin/bash DATE=`date +%d_%m_%Y` FILETYPE=.log nohup /usr/bin/perl /wde/wde_reader.pl /dev/ttyUSB0 /media/weatherlog/$DATE$FILETYPE </dev/null >/wde/wde1_reader.out & echo $! >/wde/wde_reader.pid
This script is a cutted version from tdressler.net. Instead of writing things into 2 files and other things this script will only write 1 file with a single outputline, started with the date and time.
#!/usr/bin/env perl use strict; use IO::Handle; use Time::Piece; my $dev=$ARGV[0]||'/dev/ttyUSB0'; my $socat='/usr/bin/socat'; my $cmd="$socat $dev,b9600 STDOUT |"; my $log=$ARGV[1]||"/tmp/wde1.log"; $SIG{QUIT}=$SIG{INT}=$SIG{TERM}=\&handler; $SIG{HUP}=$SIG{PIPE}='IGNORE'; $|=1; open (S,$cmd) ||die "Cannot open $dev using $cmd ($!)\n"; open(R,">>","$log") ||die "Cannot open logfile $log!\n"; R->autoflush(1); while (<S>) { my $date = localtime->strftime('%m.%d.%Y;%H:%M:%S;'); print R "$date$_"; }
This script is killing socat everyday at 11:58 pm. Remember, it will start again at 12:02 am with a new date.
#!/bin/bash sudo kill -9 `cat /wde/wde1_reader.pid` sudo rm /wde/wde1_reader.pid
There will be a new logfile with another date everyday.
Examplefile 05_06_2015.log:
06.05.2015;16:00:26;$1;1;;34,8;71,1;;;33,1;;;;33;;;;39;;;;;;;;;0 06.05.2015;16:00:26; 06.05.2015;16:02:06;$1;1;;34,8;71,1;;;33,1;;;;33;;;;39;;;;;;;;;0 06.05.2015;16:02:06; 06.05.2015;16:02:29;$1;1;;34,8;71,0;;;33,1;;;;33;;;;39;;;;;;;;;0 06.05.2015;16:02:29; 06.05.2015;16:03:24;$1;1;;34,8;71,0;;;33,1;;;;33;;;;39;;;;;;;;;0 06.05.2015;16:03:24; 06.05.2015;16:04:58;$1;1;;34,8;71,0;;;33,0;;;;33;;;;36;;;;;;;;;0 06.05.2015;16:04:58; 06.05.2015;16:05:24;$1;1;;34,8;71,0;;;33,0;;;;33;;;;36;;;;;;;;;0 06.05.2015;16:05:24; 06.05.2015;16:06:22;$1;1;;34,8;71,0;;;33,0;;;;33;;;;36;;;;;;;;;0 06.05.2015;16:06:22;
Discussion