#!/bin/bash
# /usr/local/bin/watchlogs
# http://crystalfaeries.net/posix/bin/watchlogs
# celeste:crystalfaery WATCHLOGS 2016-08-30 21:51:45+00:00
# monitor logs in the background
# we take an optional -k argument to simply kill running watches
help=6 # of header lines to spew as "help" (number of this line -1)
while [ $# != 0 ]
do # iterate arguments
case "$1" in
-h)
head -n $help $0
exit
;;
--help)
head -n $help $0
exit
;;
-v)
tail -n +4 $0 | head -n 1
exit
;;
--version)
tail -n +4 $0 | head -n 1
exit
;;
-k)
pkill acpitail
pkill tail
pkill journalctl
exit
;;
*)
echo "$0 does not cognize $1"
exit
;;
esac
shift # consume argument
done # iterating arguments
# We really should learn the standard RUN / PID protocols...
# Kill our previous execution so that:
# * we cease tailing wgets no longer running
# * we begin tailing wgets started since then
# same for journalctl so we don't run multiple copies
pkill acpitail
pkill tail
pkill journalctl
if [ \! -r /home/`whoami`/.monitor.txt ]
then # default logs:
echo /home/`whoami`/.rawdog/log.txt >> /home/`whoami`/.monitor.txt
echo /home/downloads/youtube.com/.youlog.txt >> /home/`whoami`/.monitor.txt
echo /usr/local/share/ag/silverlog.txt >> /home/`whoami`/.monitor.txt
echo /var/log/apache2/access.log >> /home/`whoami`/.monitor.txt
echo /var/log/apache2/error.log >> /home/`whoami`/.monitor.txt
echo /var/log/apache2/other_vhosts_access.log >> /home/`whoami`/.monitor.txt
echo /var/log/chronicle.log >> /home/`whoami`/.monitor.txt
echo /var/log/darchive.log >> /home/`whoami`/.monitor.txt
echo /var/log/dar.log >> /home/`whoami`/.monitor.txt
echo /var/log/feed2imap.log >> /home/`whoami`/.monitor.txt
echo /var/log/messages >> /home/`whoami`/.monitor.txt
echo /var/log/rsnapshot.log >> /home/`whoami`/.monitor.txt
echo /var/log/syncup.log >> /home/`whoami`/.monitor.txt
fi
echo "======= `/usr/local/bin/now` ======= $0 ======="
echo -n "tail -n 1 -F " >> /tmp/$$.txt
for domain in $(ps -ef --forest | grep wg[e]t | grep -v " sed " | sed 's/https:\/\/// ; s/http:\/\/// ; s/^.* // ; s/\/.*$//' | sort -u)
do
if [ -r /home/downloads/$domain/.wget.txt ]
then
echo -n "/home/downloads/$domain/.wget.txt " >> /tmp/$$.txt
else
echo "`/usr/local/bin/now` $0: /home/downloads/$domain/.wget.txt not readable." 1>&2
fi
done
for f in $(cat /home/`whoami`/.monitor.txt)
do
echo -n "$f " >> /tmp/$$.txt
done
journalctl -f & # tail systemd in background
`cat /tmp/$$.txt` & # tail non-systemd in background
acpitail & # tail acpi in background
syntax highlighted by Code2HTML, v. 0.9.1