blob: 161a50b895b49294df44a4e156aed2bcdb0a35a8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#!/bin/bash
#
# Copyright 2010 David Vazgenovich Shakaryan <dvshakaryan@gmail.com>
# Distributed under the terms of the GNU General Public License v3
CACHEDIR="${HOME}/.cache/lognotify"
CONFIGDIR="${HOME}/.config/lognotify"
if [ $# != 1 ]; then
echo "$0: incorrect number of arguments" >&2
exit 1
fi
IDENTIFIER="$1"
source "${CONFIGDIR}/${IDENTIFIER}"
# 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
|