summaryrefslogtreecommitdiff
path: root/scripts/vyatta-monitor-background
blob: 8a5c0cf0c786b254794fd0c1ae292f70e32067b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
declare awkmatch="$2"
declare pidname="$1"
if [ ! -d /var/run/vyatta/monitor ]; then
  sudo mkdir -p /var/run/vyatta/monitor
  sudo chmod -R 777 /var/run/vyatta/monitor
fi
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