summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2010-09-26 22:40:54 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2010-09-26 22:40:54 -0700
commit055e4ba09cd49b2fb8fdbd2119481e86554e1d81 (patch)
treed4ff5d8a0f61013f87636e87a8bfa6bc4d85cfc4
downloadlognotify-055e4ba09cd49b2fb8fdbd2119481e86554e1d81.tar.gz
lognotify-055e4ba09cd49b2fb8fdbd2119481e86554e1d81.tar.xz
Add script; works fine, but not ready for use.
-rwxr-xr-xlognotify.sh48
1 files changed, 48 insertions, 0 deletions
diff --git a/lognotify.sh b/lognotify.sh
new file mode 100755
index 0000000..ba14cc3
--- /dev/null
+++ b/lognotify.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+#
+# Copyright 2010 David Vazgenovich Shakaryan <dvshakaryan@gmail.com>
+# Distributed under the terms of the GNU General Public License v3
+
+if [ $# != 3 ]; then
+ echo "$0: incorrect number of arguments" >&2
+ exit 1
+fi
+
+IDENTIFIER="$1"
+SERVER="$2"
+LOGPATH="$3"
+
+CACHEDIR="${HOME}/.cache/lognotify"
+
+# Setup cache directory if nonexistent.
+if [ ! -d "${CACHEDIR}" ]; then
+ echo -n "* Creating cache directory... "
+ mkdir -p "${CACHEDIR}"
+ echo "Done"
+fi
+
+if [ ! -f "${CACHEDIR}/${IDENTIFIER}" ]; then
+ echo -n "* Creating cache file for log... "
+ touch "${CACHEDIR}/${IDENTIFIER}"
+ echo "Done"
+fi
+
+echo -n "* Determining number of lines in cached log... "
+LINES=$(wc -l "${CACHEDIR}/${IDENTIFIER}" | cut -f1 -d' ')
+echo "${LINES}"
+
+echo -n "* Acquiring new lines via SSH... "
+if [ "${LINES}" == 0 ]; then
+ LOGAPPEND=$(ssh ${SERVER} "cat ${LOGPATH}")
+else
+ LOGAPPEND=$(ssh ${SERVER} "cat ${LOGPATH} | sed -e '1,${LINES}d'")
+fi
+echo "Done"
+
+if [ -n "${LOGAPPEND}" ]; then
+ echo "* Number of new lines: $(echo "${LOGAPPEND}" | wc -l)"
+ echo
+ echo "${LOGAPPEND}" | tee -a "${CACHEDIR}/${IDENTIFIER}"
+else
+ echo "* No new lines found."
+fi