summaryrefslogtreecommitdiff
path: root/scripts/vyatta-monitor-list
blob: 6862f03e65d11874e5333b6023fdf98b0cfcd8b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
declare CURRENT_PTS=$(tty | sed -e s-/--g -e s/dev//g)
declare CURRENT_UID=$(id -u)
declare -a MPIDS
MPIDS=( $(ls /var/run/vyatta/monitor/*.pid 2>/dev/null) )

for pidfile in "${MPIDS[@]}"; do
  pid=$(<$pidfile)
  procname=$(cat /proc/$pid/cmdline 2>/dev/null)
  if [[ "$procname" =~ "tail" ]] ; then
    pts=${pidfile##*-pts}
    pts=${pts%%.pid}
    if [[ "pts$pts" == "$CURRENT_PTS" ]]; then
      if cat /proc/$pid/status | grep -q "Uid:.*$CURRENT_UID" ; then 
        print=${pidfile##*/}
        print=${print%%-pts$pts*}
        echo $print
      fi
    fi
  fi
done