Showing posts with label DBA Notes-commands. Show all posts
Showing posts with label DBA Notes-commands. Show all posts

Thursday, 24 October 2013

Capture top 10 cpu and memory Utilizing Processes when cpu reaches threshold

#!/bin/sh



# This script will check for load above 80% and notify the support admin team as per the email define in TO varaible.



DATE=`date +%y%m%d-%H%M%S`



# Check the Load on the host



if [ `uptime | awk '{ print$10 }' | cut -d. -f1` -gt 80 ];

then

        echo "============================================" >> /tmp/CPUload_$DATE



# Get a list of top 10 processes currently utilising the most CPU.





echo "List of Top Process:" /tmp/CPUload_$DATE

echo " " >> /tmp/CPUload_$DATE

echo " " >> /tmp/CPUload_$DATE

        `ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 >> /tmp/CPUload_$DATE `



        # Alert Support personnel about CPU as well the top 10 processes using most CPU







        echo " " >> /tmp/CPUload_$DATE

        echo " " >> /tmp/CPUload_$DATE

     



        echo "List of Top 10 Mmemory Consuming Processes"  >> /tmp/CPUload_$DATE

        echo " " >> /tmp/CPUload_$DATE

        echo " " >> /tmp/CPUload_$DATE

       `ps axo %mem,pid,euser,cmd | sort -nr | head -n 10  >> /tmp/CPUload_$DATE `



       





        echo " " >> /tmp/CPUload_$DATE

        echo " " >> /tmp/CPUload_$DATE

        echo "Load averages during this time" >> /tmp/CPUload_$DATE

        echo " " >> /tmp/CPUload_$DATE

        echo " " >> /tmp/CPUload_$DATE

        uptime >> /tmp/CPUload_$DATE

        echo " " >> /tmp/CPUload_$DATE

        echo " " >> /tmp/CPUload_$DATE

        free -m >> /tmp/CPUload_$DATE

else


mem=`free -b | awk '{ print$4}'`



echo $mem | cut -c7-



mem1=`echo $mem | cut -c7- `



x1=`echo $mem1 | cut -d " " -f1`

x2=`echo $mem1 | cut -d " " -f2`

x3=`echo $mem1 | cut -d " " -f3`



free=`expr $x1 + $x2`

  if [ $free -lt 512000000 ];



     then

       # Get a list of top 10 processes currently utilising the most CPU.

        echo "List of Top Process:" >> /tmp/MemLoad_$DATE

         echo " " >> /tmp/MemLoad_$DATE

         echo " " >> /tmp/MemLoad_$DATE

        `ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 >> /tmp/MemLoad_$DATE `

         # Alert Support personnel about CPU as well the top 10 processes using most CPU

         echo " " >> /tmp/MemLoad_$DATE

         echo " " >> /tmp/MemLoad_$DATE

         echo "List of Top 10 Mmemory Consuming Processes"  >> /tmp/MemLoad_$DATE

          echo " " >> /tmp/MemLoad_$DATE

          echo " " >> /tmp/MemLoad_$DATE

         `ps axo %mem,pid,euser,cmd | sort -nr | head -n 10  >> /tmp/MemLoad_$DATE `
          echo " " >> /tmp/MemLoad_$DATE

          echo " " >> /tmp/MemLoad_$DATE

          echo "Load averages during this time" >> /tmp/MemLoad_$DATE

           echo " " >> /tmp/MemLoad_$DATE

            echo " " >> /tmp/MemLoad_$DATE

            uptime >> /tmp/MemLoad_$DATE

            echo " " >> /tmp/MemLoad_$DATE

            echo " " >> /tmp/MemLoad_$DATE

            free -m >> /tmp/MemLoad_$DATE

     else

              continue

      fi

fi

find '/tmp' -name '/tmp/CPUload*' -mtime +3 -exec rm {} \;

find '/tmp' -name '/tmp/MemLoad*' -mtime +3 -exec rm {} \;

exit

Monday, 21 March 2011

Useful UNIX Commands For DBA's

Most often than not you would find yourself looking for System specs like RAM, Disk, etc while troubleshooting certain issues or for that matter general maintenance. Here's a list of commands I find useful.

Physical Ram on Linux:. cat /proc/meminfo or free -m

Physical RAM on Solaris: /usr/sbin/prtconf | grep Memory or sar -r 5 10

Physical RAM on AIX: svmon -G

Check Swap Space: swap -l

CPU : cat /proc/cpuinfo

Check Disk: du -sk, df -hk

Checking I/O: iostat -c 2 10

Check system Resource Usage: vmstat 2 10

General system Performance: top or uptime

Unzip cpio or tar files: cpio -idmvc < filename , tar -xvf filenmae

Killing a Unix Process:
kill -9 or
kill -9 `ps -ef|grep -v ksh|grep |awk '{ print $2}'`


Find a file Cointaing the search word in Current Dir:

find . -exec grep "serach word" '{}' \; -print

Ports currently used:
 netstat -na|grep 

Delete files older than a timestamp:
find . -type f -mtime +15 -print -exec rm -f {} \  -> Could replace rm with ls
Based on access time:
find . -type f –atime +20 –print -exec rm -f {} \;

Script to find files greater than a Size threshold:

for i  in `find . -name "*.log*" -exec ls -1tr {} \;`
do
  #echo "Checking the size in current directory"
  size=`ls -ltr $i  | awk '{print $5}'`
  if [ $size -gt $THRESHOLD ];
    then
     echo "File \" $i \" is greater than the Treshold"
     ls -ltr $i
  fi
done

Some vi string commands:

:g/$/s//hello   -----append end of each line

:1,$ s/^/hello/ ----- start of each line

:g/ok/s//hi/gc-----replace ok with hi globally, c is optional that requires you to enter y or n to replace or not.

Refer: http://www.cs.colostate.edu/helpdocs/vi.html for additional help

Install a Linux Package:
rpm -ivh

To check if a Package is installed:
rpm -qa|grep

Check Hostname:
hostname -a

To configure Hostname :
Hostname

Check following for N/W Config:
/etc/hosts, /etc/sysconfig/network, /etc/sysconfig/network-scripts/ifcfg-eth0, /etc/resolv.conf

Start and Stop services in Linux: service network start/stop/restart -->network here is Service name