summaryrefslogtreecommitdiff
path: root/lognotify.sh
diff options
context:
space:
mode:
Diffstat (limited to 'lognotify.sh')
-rwxr-xr-xlognotify.sh19
1 files changed, 11 insertions, 8 deletions
diff --git a/lognotify.sh b/lognotify.sh
index f291c50..6c29a8f 100755
--- a/lognotify.sh
+++ b/lognotify.sh
@@ -10,16 +10,14 @@
# Retrieve additions to remote log files via SSH. Log files are cached locally
# and only new lines are fetched from the server.
+# Location of the cache and configuration directories.
CACHEDIR="${HOME}/.cache/lognotify"
CONFIGDIR="${HOME}/.config/lognotify"
-if [ $# != 1 ]; then
- echo "$0: incorrect number of arguments" >&2
- exit 1
-fi
-
+# At the present, only the first argument is used. This may change later.
IDENTIFIER="$1"
+# Load settings from configuration file.
if [ -f "${CONFIGDIR}/${IDENTIFIER}" ]; then
source "${CONFIGDIR}/${IDENTIFIER}"
else
@@ -27,31 +25,36 @@ else
exit 1
fi
-# Setup cache directory if nonexistent.
+# Create cache directory, if nonexistent.
if [ ! -d "${CACHEDIR}" ]; then
echo -n "* Creating cache directory... "
mkdir -p "${CACHEDIR}"
echo "Done"
fi
+# Create cache file, if nonexistent.
if [ ! -f "${CACHEDIR}/${IDENTIFIER}" ]; then
echo -n "* Creating cache file for log... "
touch "${CACHEDIR}/${IDENTIFIER}"
echo "Done"
fi
+# Determine number of lines in cache file.
echo -n "* Determining number of lines in cached log... "
LINES=$(wc -l "${CACHEDIR}/${IDENTIFIER}" | cut -f1 -d' ')
echo "${LINES}"
+# Acquire new lines via SSH.
echo -n "* Acquiring new lines via SSH... "
if [ "${LINES}" == 0 ]; then
- LOGAPPEND=$(ssh ${SSH_OPTIONS} ${SSH_HOSTNAME} "cat ${LOGPATH}")
+ COMMAND="cat ${LOGPATH}"
else
- LOGAPPEND=$(ssh ${SSH_OPTIONS} ${SSH_HOSTNAME} "cat ${LOGPATH} | sed -e '1,${LINES}d'")
+ COMMAND="cat ${LOGPATH} | sed -e '1,${LINES}d'"
fi
+LOGAPPEND=$(ssh ${SSH_OPTIONS} ${SSH_HOSTNAME} "${COMMAND}")
echo "Done"
+# Output new lines, and append them to the cache file.
if [ -n "${LOGAPPEND}" ]; then
echo "* Number of new lines: $(echo "${LOGAPPEND}" | wc -l)"
echo "${LOGAPPEND}" | tee -a "${CACHEDIR}/${IDENTIFIER}"