diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2010-09-27 18:56:39 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2010-09-27 18:56:39 -0700 |
commit | 1b84d1c47893f08b59211d13df8849ac8a7ce791 (patch) | |
tree | 0fd72ee8943cda1067a3add2d868f392e1ecb2a3 | |
parent | c536de67b14fd943f937be7bc84b099186632bc1 (diff) | |
download | lognotify-1b84d1c47893f08b59211d13df8849ac8a7ce791.tar.gz lognotify-1b84d1c47893f08b59211d13df8849ac8a7ce791.tar.xz |
Some minor changes, and add comments.
-rwxr-xr-x | lognotify.sh | 19 |
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}" |