[HPADM] 100% CPU Script

From: Joe Crawford (abjcrawford@yahoo.com)
Date: Tue Jan 18 2005 - 11:48:38 EST


Team:

Thanks much for the responses for my earlier question
reg 100% CPU (I guess the problem was with nslookup
command going in infinite loop following the dns
failure). I have attached the script for some comments
from the Gurus. Please advise.

Best Regards

Joe.

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

#!/sbin/sh
######################################################################
#
# Script
# Name: update_hostlist_rhosts.sh
#
# Comments: This script get the master & slave nclass server list
# and it overwrites the .rhosts file under all the
# user's home directory with the updated list. This script runs once in
# a day through the cronjob.
#
#
#
################## MODIFICATION HISTORY ###############################
# AUTHOR DATE CHANGED CHANGE HISTORY VERSION
#-----------------------------------------------------------------------------
# Changed the logic to get
# the Master & Slave host
# Modified the logic to take user's home directory
# from /etc/passwd.nis file
# Modified the logic to take full host name to put in to the
# users .rhosts file
#
###############################################################################

Add_rhost_entry()
{
   user_group="CITRIX"
   hostlist=`cat /tmp/hostlist`
   no_lines=`cat /etc/passwd.nis | wc -l`
   cur_line=1
   while [ $cur_line -le $no_lines ]
   do
   one=`cat /etc/passwd.nis | head -$cur_line | tail -1`
   user_id=`echo $one| awk -F':' '{print $1}'`
   HomeDir=`echo $one| awk -F':' '{print $6}'`
   GroupID=`echo $one| awk -F':' '{print $4}'`
       if [ -d $HomeDir -a $GroupID = 500 ]
       then
      for hostname in $hostlist
      do
                  # Added to have full host name with domain in users .rhosts file
                  full_host=`/usr/bin/nslookup $hostname | grep -v "Name Server" | grep Name | cut -f2 -d":" | xargs`
                  grep "$full_host $user_id" $HomeDir/.rhosts >/dev/null 2>&1
                  if [ $? -ne 0 ]
                  then
                     echo "$full_host $user_id" >> $HomeDir/.rhosts
         fi

                  full_host_ip=`getip $full_host`
                  grep "$full_host_ip $user_id" $HomeDir/.rhosts >/dev/null 2>&1
                  if [ $? -ne 0 ]
                  then
                     echo "$full_host_ip $user_id" >> $HomeDir/.rhosts
         fi
      done
      chmod 600 $HomeDir/.rhosts
      chown $user_id:$user_group $HomeDir/.rhosts
      fi
   let cur_line=$cur_line+1
   done
   rm /tmp/hostlist 2>/dev/null
}

get_hostlist()
{
   ypwhich -m ypservers>/tmp/hostlist
   ypcat ypservers | grep -v `ypwhich -m ypservers` | tr -s " " "\n">>/tmp/hostlist
}

######################################################################
#
# MAIN SCRIPT
#
######################################################################
echo "##################`date`#################"
get_hostlist
Add_rhost_entry

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:45 EDT