This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| linux:raspberry:wde:scripts:reader [2015/06/08 11:10] – lunetikk | linux:raspberry:wde:scripts:reader [2019/12/10 14:43] (current) – [Script 3 - Killer] lunetikk | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| ==== Script 1 - Starter ==== | ==== Script 1 - Starter ==== | ||
| - | This will execute socat with daily modified parameters. The logfile parameter will have the date of " | + | This will execute socat with daily modified parameters. The logfile parameter will have the date of " |
| - | < | + | < |
| #!/bin/bash | #!/bin/bash | ||
| Line 13: | Line 13: | ||
| FILETYPE=.log | FILETYPE=.log | ||
| - | nohup /usr/bin/perl / | + | if [ -f "/media/weatherlog/$DATE$FILETYPE" |
| + | echo "" | ||
| + | else | ||
| + | echo " | ||
| + | fi | ||
| + | |||
| + | nohup / | ||
| echo $! >/ | echo $! >/ | ||
| </ | </ | ||
| Line 19: | Line 25: | ||
| ==== Script 2 - Reader ==== | ==== Script 2 - Reader ==== | ||
| - | This script is a cutted version from [[http:// | + | This script will write 1 file with a single outputline, started with the date and time. |
| - | < | + | < |
| - | #!/usr/bin/env perl | + | #!/bin/bash |
| - | use strict; | + | DATE=`date +%d_%m_%Y` |
| - | use IO:: | + | FILETYPE=.log |
| - | use Time:: | + | |
| - | my $dev=$ARGV[0]||' | + | FILE=/media/weatherlog/$DATE$FILETYPE |
| - | my $socat=' | + | |
| - | my $cmd="$socat $dev,b9600 STDOUT |"; | + | |
| - | my $log=$ARGV[1]||"/ | + | |
| + | SOCAT=/ | ||
| + | DEV=/ | ||
| + | BAUD=\, | ||
| + | CMD=" | ||
| - | $SIG{QUIT}=$SIG{INT}=$SIG{TERM}=\& | + | while read -r line |
| - | $SIG{HUP}=$SIG{PIPE}=' | + | do |
| - | + | | |
| - | $|=1; | + | done < <( $CMD ) |
| - | + | ||
| - | open (S,$cmd) ||die "Cannot open $dev using $cmd ($!)\n"; | + | |
| - | open(R,">>"," | + | |
| - | + | ||
| - | R-> | + | |
| - | + | ||
| - | while (<S>) { | + | |
| - | my $date = localtime-> | + | |
| - | print R "$date$_"; | + | |
| - | } | + | |
| </ | </ | ||
| ==== Script 3 - Killer ==== | ==== Script 3 - Killer ==== | ||
| - | This script is killing socat everyday at 11:58 pm. Remember, it will start again at 12:02 am with a new date. | + | 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 | #!/bin/bash | ||
| - | sudo kill -9 `cat /wde/wde1_reader.pid` | + | sudo kill -9 `cat /wde/wde_reader.pid` |
| - | sudo rm /wde/wde1_reader.pid | + | sudo rm /wde/wde_reader.pid |
| </ | </ | ||
| ==== Output ==== | ==== Output ==== | ||
| - | There will be a new logfile with another date everyday. | + | There will be a new logfile with another date everyday. |
| + | |||
| + | Examplefile 06_05_2015.log: | ||
| - | Examplefile 05_06_2015.log: | ||
| < | < | ||
| 06.05.2015; | 06.05.2015; | ||
| - | 06.05.2015; | ||
| 06.05.2015; | 06.05.2015; | ||
| - | 06.05.2015; | ||
| 06.05.2015; | 06.05.2015; | ||
| - | 06.05.2015; | ||
| 06.05.2015; | 06.05.2015; | ||
| - | 06.05.2015; | ||
| 06.05.2015; | 06.05.2015; | ||
| - | 06.05.2015; | ||
| 06.05.2015; | 06.05.2015; | ||
| - | 06.05.2015; | ||
| 06.05.2015; | 06.05.2015; | ||
| - | 06.05.2015; | ||
| </ | </ | ||
| + | |||
| + | \\ | ||
| + | ~~DISCUSSION: | ||
| + | |||
| + | |||