This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
linux:raspberry:wde:scripts:reader [2015/06/15 15:42] – lunetikk | linux:raspberry:wde:scripts:reader [2017/12/08 20:49] – lunetikk | ||
---|---|---|---|
Line 7: | Line 7: | ||
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 " | ||
- | <code sh wde.sh> | + | wde.sh |
+ | |||
+ | <code bash> | ||
#!/bin/bash | #!/bin/bash | ||
Line 13: | Line 15: | ||
FILETYPE=.log | FILETYPE=.log | ||
- | nohup /usr/bin/perl / | + | if [ -f "/media/weatherlog/$DATE$FILETYPE" |
+ | echo "" | ||
+ | else | ||
+ | echo " | ||
+ | fi | ||
+ | |||
+ | nohup / | ||
echo $! >/ | echo $! >/ | ||
</ | </ | ||
Line 19: | Line 27: | ||
==== 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. |
- | <code perl wde_reader.pl> | + | wde_reader.sh |
- | # | + | |
- | use strict; | + | <code bash> |
- | use IO:: | + | #!/bin/bash |
- | use Time:: | + | |
- | my $dev=$ARGV[0]||'/ | + | DATE=`date +%d_%m_%Y` |
- | my $socat='/ | + | FILETYPE=.log |
- | my $cmd=" | + | |
- | my $log=$ARGV[1]||"/ | + | |
- | + | ||
- | + | ||
- | $SIG{QUIT}=$SIG{INT}=$SIG{TERM}=\& | + | |
- | $SIG{HUP}=$SIG{PIPE}=' | + | |
- | $|=1; | + | FILE=/ |
- | open (S,$cmd) ||die " | + | SOCAT=/ |
- | open(R,">>", | + | DEV=/dev/ttyUSB0 |
+ | BAUD=\,b9600 | ||
+ | CMD="$SOCAT $DEV$BAUD STDOUT" | ||
- | R-> | + | while read -r line |
- | + | do | |
- | while (<S>) { | + | echo "$(date +' |
- | my $date = localtime-> | + | done < <( $CMD ) |
- | print R "$date$_"; | + | |
- | } | + | |
</ | </ | ||
Line 54: | Line 54: | ||
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:58 pm. Remember, it will start again at 12:02 am with a new date. | ||
- | <code sh wdekill.sh> | + | wdekill.sh |
- | #!/bin/bash | + | |
- | sudo kill -9 `cat / | + | <code bash> |
- | sudo rm /wde/wde1_reader.pid | + | #!/bin/bash |
+ | sudo kill -9 `cat / | ||
+ | sudo rm / | ||
</ | </ | ||
==== 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~~ | ~~DISCUSSION~~ | ||
+ | |||
+ |