0
Shell :: Simple Apache Pig Identification
Jan 28, 2010
In Uncategorized
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #!/bin/bash #apachepig.sh #simple script for identifying shared hosting pigs on a small server #only definitive for a forking server, threading would need modification #should be enhanced for polling, but useful for processes that are hung #which is what we are looking for right? ARGS=("$@") #GLOBALS WEBROOT=/home DAEMONNAME=apache2 #ARGS ACTION=${ARGS[0]} #add single PID functionality later PID=${ARGS[1]} case $ACTION in mem) PROCESSES=$(top -b -n1 | grep $DAEMONNAME | sort -r -k 6) ;; cpu) PROCESSES=$(top -b -n1 | grep $DAEMONNAME | sort -r -k 5) ;; time) PROCESSES=$(top -b -n1 | grep $DAEMONNAME | sort -r -k 7) ;; *) echo "operation not supported" ;; esac IFS=$'\n' for x in $PROCESSES; do echo "$x" PID=$(echo $x | awk '{print $1}') OUTPUT=$(lsof -w -p $PID | grep "$WEBROOT") if [ $OUTPUT ]; then echo $OUTPUT else echo 'NO PIGS' fi echo " " done |