From 48d0fd96aaec9dc156523be26148c4e8f261cd39 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 28 Sep 2010 01:40:21 -0700 Subject: Add skeleton Ruby script to replace shell script. --- lognotify.rb | 8 ++++++ lognotify.sh | 79 ------------------------------------------------------------ 2 files changed, 8 insertions(+), 79 deletions(-) create mode 100644 lognotify.rb delete mode 100755 lognotify.sh diff --git a/lognotify.rb b/lognotify.rb new file mode 100644 index 0000000..cc2a975 --- /dev/null +++ b/lognotify.rb @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +# +# lognotify.rb +# http://github.com/omp/lognotify +# +# Copyright 2010 David Vazgenovich Shakaryan +# Distributed under the terms of the GNU General Public License v3. +# See http://www.gnu.org/licenses/gpl.txt for the full license text. diff --git a/lognotify.sh b/lognotify.sh deleted file mode 100755 index e92ff02..0000000 --- a/lognotify.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/bash -# -# lognotify.sh -# http://github.com/omp/lognotify -# -# Copyright 2010 David Vazgenovich Shakaryan -# Distributed under the terms of the GNU General Public License v3. -# See http://www.gnu.org/licenses/gpl.txt for the full license text. -# -# Retrieve additions to remote log files via SSH. Log files are cached locally -# and only new lines are fetched from the server. -# -# To use, create a configuraton file, such as ~/.config/lognotify/identifier, -# with the following settings: -# -# SSH_OPTIONS="" Options for SSH command. [Can be empty.] -# SSH_HOSTNAME="" Hostname of SSH server. -# LOGPATH="" Path of log file on server. -# -# Afterwards, simply run the script with the identifier as an argument: -# -# lognotify.sh identifier -# -# During the initial run, a cache file will be created and all lines will be -# retrieved. On any subsequent runs, only new lines will be retrieved and -# outputted, as well as appended to the cache file, which should be identical -# to the log file on the sever. - -# Location of the cache and configuration directories. -CACHEDIR="${HOME}/.cache/lognotify" -CONFIGDIR="${HOME}/.config/lognotify" - -# 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 - echo "$0: configuration file not found" >&2 - exit 1 -fi - -# 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 - COMMAND="cat ${LOGPATH}" -else - 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}" -else - echo "* No new lines in log." -fi -- cgit v1.2.3-70-g09d2