udevadm
[usb-wde1-tools.git] / munin / usb-wde1-log-last.sh
1 #!/bin/sh
2 # logs the last line. usable via nohup on the server
3 #
4 # run this script as follows:
5 # $ nohup ./usb-wde1-log-last.sh &
6 #
7 # Use --dummy-data as parameter to log dummy data only
8 #
9 # License: http://www.gnu.org/licenses/agpl.html AGPL
10 # Author: Christian Weiske <cweiske@cweiske.de>
11 #
12 # FIXME: send RESET or INIT and M2
13
14 device=/dev/ttyUSB0
15
16 if [ ! -d /var/spool/usb-wde1 ]; then
17     mkdir /var/spool/usb-wde1
18 fi
19
20 curdir="$(dirname "$0")"
21 if [ "$1" = "--dummy-data" ]; then
22     $curdir/../dummy-data-generator.php\
23      | $curdir/log-single-line.sh /var/spool/usb-wde1/usb-wde1-last
24 else
25     if [ ! -r $device ]; then
26         echo "Device $device is not readable"
27         exit 1
28     fi
29
30     #socat breaks something that leads to
31     # WRONG VAL, WRONG CMD and FullBuff->Reset
32     # errors
33     socat $device,b9600,min=1,time=1,brkint=0,icrnl=0,ixoff=1,imaxbel=0,opost=0,isig=0,icanon=0,iexten=0,echo=0,echoe=0,echok=0 STDOUT\
34      | $curdir/log-single-line.sh /var/spool/usb-wde1/usb-wde1-last
35 fi