summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJohn Southworth <john.southworth@vyatta.com>2011-09-02 12:27:07 -0500
committerJohn Southworth <john.southworth@vyatta.com>2011-10-27 17:11:28 -0500
commit12b09b2a196a00389d4e1b1996fcf29689141920 (patch)
tree912da53f472d43176641cde17f4db688d18a86f7 /scripts
parent7106043d374852bd104d0a4e41a0d23562533731 (diff)
downloadvyatta-op-12b09b2a196a00389d4e1b1996fcf29689141920.tar.gz
vyatta-op-12b09b2a196a00389d4e1b1996fcf29689141920.zip
Initial monitor vpn implementation. Other montior commands will be build on these scripts
(cherry picked from commit 334a6fab05b5e51097010b1da41fca32df7b8959)
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/vyatta-monitor7
-rwxr-xr-xscripts/vyatta-monitor-background19
-rwxr-xr-xscripts/vyatta-monitor-background-stop13
3 files changed, 39 insertions, 0 deletions
diff --git a/scripts/vyatta-monitor b/scripts/vyatta-monitor
new file mode 100755
index 0000000..22867e8
--- /dev/null
+++ b/scripts/vyatta-monitor
@@ -0,0 +1,7 @@
+#!/bin/bash
+declare awkmatch="$2"
+for i in "${@:3}"; do
+ awkmatch+="|$i"
+done
+tail -f /var/log/messages \
+ | awk "/$awkmatch/{ \$5=\" $1:\"; for (f=5; f<=NF; ++f) {printf(\"%s \", \$f);}; printf(\"\n\") }"
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
diff --git a/scripts/vyatta-monitor-background-stop b/scripts/vyatta-monitor-background-stop
new file mode 100755
index 0000000..c10528f
--- /dev/null
+++ b/scripts/vyatta-monitor-background-stop
@@ -0,0 +1,13 @@
+#!/bin/bash
+declare pidname="$1"
+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
+ kill -9 $pid
+ rm -f $pidfile
+ exit 0
+ fi
+fi
+echo -ne "\n You are not currently monitoring this service\n\n"