Advertisement
devinteske

psdiff4.sh

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