diff options
Diffstat (limited to 'scripts/vyatta-monitor-background')
-rwxr-xr-x | scripts/vyatta-monitor-background | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/scripts/vyatta-monitor-background b/scripts/vyatta-monitor-background new file mode 100755 index 0000000..fc6c19c --- /dev/null +++ b/scripts/vyatta-monitor-background @@ -0,0 +1,19 @@ +#!/bin/bash +declare awkmatch="$2" +declare pidname="$1" +for i in "${@:3}"; do + awkmatch+="|$i" +done +pidfile="/var/run/vyatta/monitor/$pidname-`tty| sed -e s-/--g -e s/dev//g`.pid" +if [ -f $pidfile ]; then + pid=$(cat $pidfile) + processname=$(cat /proc/$pid/cmdline 2>/dev/null) + if [[ $processname =~ "tail" ]];then + echo -ne "\n You are already monitoring this service\n\n" + exit 0 + fi +fi +{ ( tail -f -n0 /var/log/messages & echo $! >&3) 3> \ + $pidfile \ + | awk "/$awkmatch/{ \$5=\" $1:\"; for (f=5; f<=NF; ++f) {printf(\"%s \", \$f);}; printf(\"\n\") }" 2>&3 & \ +} 3>&2 2>/dev/null; disown |