Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- ############################################################ IDENT(1)
- #
- # $Title: Script to show running processes started prior to modification $
- #
- ############################################################ INCLUDES
- BSDCFG_SHARE="/usr/share/bsdconfig"
- . "$BSDCFG_SHARE/common.subr" || exit 1
- f_include "$BSDCFG_SHARE/strings.subr"
- ############################################################ MAIN
- #
- # Initialize list of pids we care about
- # NB: We only care about pids with ucomm values copacetic to which(1)
- #
- PIDS=
- #
- # Ask ps(1) for a list of pids and their associated short command names.
- # Generate $PIDS as space-separated list of process IDs whose ucomm represents
- # a utility name accessible via $PATH expansion. For each PID, set variables
- # pidcmd_$pid containing the ucomm value (short command name).
- #
- exec <<EOI
- $( ps ax -o pid= -o ucomm= )
- EOI
- while read pid ucomm; do
- f_which "$ucomm" pidcmd || continue
- [ -r "$pidcmd" ] || continue
- PIDS="$PIDS $pid"
- setvar pidcmd_$pid "$pidcmd"
- done
- exec <&1
- #
- # Ask ps(1) for the last start (lstart) date/time of each pid in $PIDS
- #
- exec <<EOI
- $( ps -o pid= -o lstart= -p $PIDS )
- EOI
- while read pid lstart; do
- setvar piddate_$pid "$( date -j -f %c "$lstart" +%s )"
- done
- exec <&1
- #
- # Ask stat(1) for the modification time (epoch) for each running utility.
- # Modification times are stored in ondiskdate_$pid.
- #
- pidcmd_list=
- for pid in $PIDS; do
- f_getvar pidcmd_$pid pidcmd
- f_shell_escape "$pidcmd" _pidcmd
- pidcmd_list="$pidcmd_list '$_pidcmd'"
- done
- exec <<EOI
- $( eval stat -f %m $pidcmd_list )
- EOI
- set -- $PIDS
- while read ondiskdate rest_ignored; do
- pid="$1"
- [ "$pid" ] || break
- setvar ondiskdate_$pid "$ondiskdate"
- shift 1 # pid
- done
- exec <&1
- #
- # Compare on-disk epoch(s) to running epoch(s) (lstart)
- #
- for pid in $PIDS; do
- f_getvar ondiskdate_$pid ondiskdate || continue
- f_getvar piddate_$pid piddate || continue
- f_getvar pidcmd_$pid pidcmd || continue
- echo "Comparing $ondiskdate and $piddate for pid $pid $pidcmd"
- [ $ondiskdate -gt $piddate ] &&
- echo "ALERT! $ondisk needs to be reloaded!"
- done
- exit 0
- ################################################################################
- # END
- ################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement