#/bin/sh ################################################ # Author: eos # Date: 13 March 2009 # Script to set off ps process system monitors # # Usage # ----- # $0 # #useage message if [ $# -eq 0 ]; then echo -e " Usage: $0m e.g. nohup $0 test1 20 100 & will initialise ps taking 100 samples at 20 second intervals. NOTE NOTE NOTE: Use \"nohup\" before command Execute in background with \" &\" This is to allow shell to continue execution if connection is broken " exit fi #Set UNIX95 Env Variable #export UNIX95=1; hostname=`hostname` #Get hostname to place in output files #variable assignments and calculations prefix=$1"."$hostname no_samples=$3 sleeptime=$2 #Calculate a suitable sample interval at which to run "who" totaltime=`echo "$no_samples*$sleeptime" | bc` psfilename=$prefix".mem.ps" psfilename2=$prefix".cpu.ps" if [ -f $psfilename ]; then rm $psfilename; fi if [ -f $psfilename2 ]; then rm $psfilename2 ; fi echo "PID PhyPages VirtkB %MEM CPUTime User Args" >> $psfilename echo "PID PPID pcup Time CPUTime Args" >> $psfilename2 pstime=0 while (( $pstime<=$totaltime )); do pstime=`echo " $sleeptime+$pstime " | bc `; date +'%H:%M:%S %b %d %y %Z' >> $psfilename; ps -eo pid,sz,vsz,%mem,time,user,args | sort -nr -k 2,3| head -60 >> $psfilename; date +'%H:%M:%S %b %d %y %Z' >> $psfilename2; ps -eo pid,ppid,%cpu,time,cputime,args | sort -nr -k 3 | head -60 >> $psfilename2; sleep $sleeptime; done