Listing 2 count_proc_ksh
1#!/bin/ksh 2function mail_to_user 3{ 4 echo $last has $count processes on host $host@ 5 iaddress=${last}"+" 6 mailaddress=`grep $iaddress /usr/local/scripts/mailusermap | tr '+' ' ' | awk \ '{print $2}'` 7 /usr/local/scripts/proc_letter $mailaddress $count $host > /tmp/pl$$ 8 /usr/local/bin/pstree -wu $last >> /tmp/pl$$ 9 /usr/local/scripts/proc_letter2 $host >> /tmp/pl$$ 10 11 cat /tmp/pl$$ | /bin/mailx -s "Urgent system letter" $mailaddress 12 rm /tmp/pl$$ 13} 14# MAIN - First get all valid processes owners 15 processes=`ps -ef | awk '{print $1}' | sort | grep -v root | grep -v daemon | \ grep -v UID` 16 limit=1 ; count=1 ; last="qwert" ; host=`hostname` 17 for i in $processes 18 do 19 userquota=`grep $last /usr/local/scripts/mailusermap | tr '+' ' ' | awk \ '{print $3}'` 20 if [[ $userquota == "" ]] then 21 userquota=999 22 fi 23 uquota=`echo $userquota | awk '{print $1}'` 24 if [[ $i != $last ]] then 25 if (( $count > $uquota )) then 26 mail_to_user 27 fi 28 count=1 29 else 30 (( count=$count + 1 )) 31 fi 32 last=$i 33 done 34 userquota=`grep $i /usr/local/scripts/mailusermap | tr '+' ' ' | awk \ '{print $3}'` 35 if [[ $userquota == "" ]] then 36 userquota=999 37 fi 38 uquota=`echo $userquota | awk '{print $1}'` 39 if (( $count > $uquota )) then 40 mail_to_user 41 fi