Advertisement
devinteske

psdiff5.sh

Aug 15th, 2014
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.09 KB | None | 0 0
  1. #!/bin/sh
  2. BSDCFG_SHARE="/usr/share/bsdconfig"
  3. . "$BSDCFG_SHARE/common.subr" || exit 1
  4. f_include "$BSDCFG_SHARE/strings.subr"
  5. PIDS= pidcmd_list=
  6. exec <<EOI
  7. $( ps ax -o pid= -o ucomm= )
  8. EOI
  9. while read pid ucomm; do
  10.     { f_which "$ucomm" pidcmd && [ -r "$pidcmd" ]; } || continue
  11.     PIDS="$PIDS $pid"
  12.     setvar pidcmd_$pid "$pidcmd"
  13. done
  14. exec <<EOI
  15. $( ps -o pid= -o lstart= -p $PIDS )
  16. EOI
  17. while read pid lstart; do
  18.     setvar piddate_$pid "$( date -j -f %c "$lstart" +%s )"
  19. done
  20. for pid in $PIDS; do
  21.     f_getvar pidcmd_$pid pidcmd
  22.     f_shell_escape "$pidcmd" _pidcmd
  23.     pidcmd_list="$pidcmd_list '$_pidcmd'"
  24. done
  25. exec <<EOI
  26. $( eval stat -f %m $pidcmd_list )
  27. EOI
  28. set -- $PIDS
  29. while read ondiskdate rest_ignored; do
  30.     [ "$1" ] || break
  31.     setvar ondiskdate_$1 "$ondiskdate"
  32.     shift 1 # pid
  33. done
  34. for pid in $PIDS; do
  35.     f_getvar ondiskdate_$pid ondiskdate &&|| continue
  36.     f_getvar piddate_$pid piddate || continue
  37.     f_getvar pidcmd_$pid pidcmd || continue
  38.     echo "Comparing $ondiskdate and $piddate for pid $pid $pidcmd"
  39.     [ $ondiskdate -gt $piddate ] &&
  40.         echo "ALERT! $ondisk needs to be reloaded!"
  41. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement