#!/bin/ksh ################################################################################ # # File to loop for processes # # Written by Matt Baker mbaker@computeranddata.com # ################################################################################ DEBUG=0 VERBOSE=0 LOOP_ITERATIONS=0 LOGFILE=/tmp/ps.out.$$ INTERVAL=2 MAX_ITERATIONS=100 SV_PSCMD="ps auxww" BSD_PSCMD="ps -elf" PSCMD=$SV_PSCMD if (( DEBUG )) then set -x fi # # usage function # usage () { print "$0 [-debug] [-v] [-p [SV | BSD] ] [-i #] [-max #] [-log /some/file]" print "" print "Defaults:" print " ps_type: -SV" print " interval: 2" print " max: 100" print " log: /tmp/ps.out.\$\$" } while (( $# )) do case "$1" in -debug) DEBUG=1 shift ;; -v) VERBOSE=1 shift ;; -log) shift LOGFILE=$1 touch $LOGFILE if (( ! $? )) then print "ERROR: Cannot create logfile $LOGFILE." print "Please correct manually or do not use this option (take default)." fi shift ;; -max) shift MAX_ITERATIONS=$1 if [[ -n $(print $MAX_ITERATIONS | grep "[a-zA-Z]") ]] then print "ERROR: Incorrect value for $MAX_ITERATIONS" print " Must be postive integer." usage fi shift ;; -i) shift INTERVAL=$1 if [[ -n $(print $INTERVAL | grep "[a-zA-Z]") ]] then print "ERROR: Incorrect value for $INTERVAL" print " Must be postive integer." usage fi shift ;; -p) shift PSCMD=$1 if [[ -z $(print $PSCMD | egrep -e "SV|BSD") ]] then print "ERROR: Incorrect option $PSCMD for -p option." print " Use either SV or BSD." usage fi shift ;; * ) print "ERROR:1:$0 Incorrect option - $1" usage exit 1 esac done # # main # if (( DEBUG )) then set -x fi print "===========================================================" \ > $LOGFILE print "$0 started on: $(date)" >> $LOGFILE # # while PATTERN exists, loop on some commands # while (( $LOOP_ITERATIONS <= $MAX_ITERATIONS )) do print "===========================================================" \ >> $LOGFILE print "current time: $(date)" >> $LOGFILE $PSCMD >> $LOGFILE sleep $INTERVAL >> $LOGFILE let LOOP_ITERATIONS+=1 >> $LOGFILE if (( VERBOSE )) then print -n "working...\c" fi done print "" print "===========================================================" \ >> $LOGFILE date >> $LOGFILE last >> $LOGFILE print "$0 stopped on: $(date)" >> $LOGFILE print "Logfile is: $LOGFILE"