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:01 am everyday.
#!/bin/bash DATE=`date +%d_%m_%Y` FILETYPE=.log if [ -f "/media/weatherlog/$DATE$FILETYPE" ]; then echo "" > /dev/null else echo "Date;Time;Column1;Column2;Column3;Column4;Column5;Column6;Column7;Column8;Column9;Column10;Column11;Column12;Column13;Column14;Column15;Column16;Column17;Column18;Column19;Column20;Column21;Column22;Column23;Column24;Column25" > /media/weatherlog/$DATE$FILETYPE fi nohup /wde/wde_reader.sh </dev/null >/wde/wde_reader.out & echo $! >/wde/wde_reader.pid
This script will write 1 file with a single outputline, started with the date and time.
#!/bin/bash DATE=`date +%d_%m_%Y` FILETYPE=.log FILE=/media/weatherlog/$DATE$FILETYPE SOCAT=/usr/bin/socat DEV=/dev/ttyUSB0 BAUD=\,b9600 CMD="$SOCAT $DEV$BAUD STDOUT" while read -r line do echo "$(date +'%d.%m.%Y;%H:%M:%S;')$line">> $FILE done < <( $CMD )
This script is killing socat everyday at 11:59 pm. Remember, it will start again at 12:01 am with a new date.
#!/bin/bash sudo kill -9 `cat /wde/wde_reader.pid` sudo rm /wde/wde_reader.pid
There will be a new logfile with another date everyday.
Examplefile 06_05_2015.log:
06.05.2015;16:00:26;$1;1;;34,8;71,1;;;33,1;;;;33;;;;39;;;;;;;;;0 06.05.2015;16:02:06;$1;1;;34,8;71,1;;;33,1;;;;33;;;;39;;;;;;;;;0 06.05.2015;16:02:29;$1;1;;34,8;71,0;;;33,1;;;;33;;;;39;;;;;;;;;0 06.05.2015;16:03:24;$1;1;;34,8;71,0;;;33,1;;;;33;;;;39;;;;;;;;;0 06.05.2015;16:04:58;$1;1;;34,8;71,0;;;33,0;;;;33;;;;36;;;;;;;;;0 06.05.2015;16:05:24;$1;1;;34,8;71,0;;;33,0;;;;33;;;;36;;;;;;;;;0 06.05.2015;16:06:22;$1;1;;34,8;71,0;;;33,0;;;;33;;;;36;;;;;;;;;0