cam scripts
authorSyed S. Albiz <ssalbiz@uwaterloo.ca>
Mon, 25 Jun 2012 02:44:10 +0000 (22:44 -0400)
committerSyed S. Albiz <ssalbiz@uwaterloo.ca>
Mon, 25 Jun 2012 02:44:10 +0000 (22:44 -0400)
camcount [new file with mode: 0755]
camwho [new file with mode: 0755]
camwhod [new file with mode: 0755]
daemon [new file with mode: 0755]
output.cc [new file with mode: 0644]

diff --git a/camcount b/camcount
new file mode 100755 (executable)
index 0000000..18f9208
--- /dev/null
+++ b/camcount
@@ -0,0 +1,16 @@
+#!/bin/bash
+TAURINE=`nslookup taurine | grep 129.97.134 | sed -e 's/Address: //'`
+CAFFIENE=`nslookup csc | grep 129.97.134 | sed -e 's/Address: //'`
+OUTPUT=/dev/ttyUSB0
+
+stty -F $OUTPUT 4800
+while [ 1 -eq 1 ];
+do
+  FOO=`netstat -n | grep 'tcp[ \t]*[0-9]*[ \t]*[0-9]*[ \t]*[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*:8081' | sed 's/tcp[ \t]*[0-9]*[ \t]*[0-9]*[ \t]*[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*:8081[ \t]*//g' | sed 's/:.*$//g' | grep -v $TAURINE | grep -v $CAFFIENE | sort -u | wc -l`
+  if [ "$OLDFOO" != "$FOO" ];
+  then
+    OLDFOO=$FOO
+    echo -n $FOO | /opt/camcount/output $OUTPUT
+  fi
+  sleep 1
+done
diff --git a/camwho b/camwho
new file mode 100755 (executable)
index 0000000..8c1d219
--- /dev/null
+++ b/camwho
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+OUTPUT_FILE=/scratch/camwho_output
+
+while [ 1 -eq 1 ];
+do
+  grep -E '(webcam HTTP|Webcams HTTP)' /var/log/apache2/access.log | \
+    grep ' 200 ' | \
+    sed 's/\].*$/]/' | \
+    sed 's/ \[.*$//' | \
+    sed 's/^.*- //' | \
+    tail > $OUTPUT_FILE
+  sleep 1
+done
diff --git a/camwhod b/camwhod
new file mode 100755 (executable)
index 0000000..221ff24
--- /dev/null
+++ b/camwhod
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+PIDFILE=/var/run/camwho.pid
+DAEMON="/bin/bash /opt/camwho/camwho"
+
+case "$1" in
+       start)
+               start-stop-daemon -S -mp $PIDFILE -x $DAEMON -b
+               ;;
+       stop)
+               start-stop-daemon -K -p $PIDFILE -x $DAEMON
+               ;;
+       restart)
+               "$0" stop
+               "$0" start
+               ;;
+       *)
+               echo "Usage: $0 (start|stop|restart)"
+               ;;
+esac
diff --git a/daemon b/daemon
new file mode 100755 (executable)
index 0000000..8f165f0
--- /dev/null
+++ b/daemon
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+PIDFILE=/opt/camcount/camcount.pid
+DAEMON=/opt/camcount/camcount
+
+case "$1" in
+       start)
+               start-stop-daemon -S -mp $PIDFILE -x $DAEMON -b
+               ;;
+       stop)
+               start-stop-daemon -K -p $PIDFILE -x $DAEMON
+               ;;
+       restart)
+               "$0" stop
+               "$0" start
+               ;;
+       *)
+               echo "Usage: $0 (start|stop|restart)"
+               ;;
+esac
diff --git a/output.cc b/output.cc
new file mode 100644 (file)
index 0000000..9a1c97f
--- /dev/null
+++ b/output.cc
@@ -0,0 +1,13 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char ** argv) {
+ if(argc != 2) { perror("arg"); abort(); }
+ int fd = open(argv[1], O_WRONLY);
+ if (fd == -1) { perror("open"); abort(); }
+ char c;
+ while (1 == scanf("%hhi", &c)) write(fd, &c, 1);
+}