Monday 6 October 2014

UNIX & AIX

1. Kill all the O.S process of a particular user | kill -9

Want to kill all the O.S process that are running under particular user.

UNIX$ ps -aef  | grep -i shaik | awk '{print $2}' | sed 's/^/kill -9 /' > 1.txt
UNIX$./1.txt

2. Copy file from source to destination when size > 0 bytes

#!/bin/ksh
wdate=`date '+%Y-%m-%d'`
wdate1=`date '+%m%d%y'`
logdate=`date '+%m%d%y%H%M%S'`
source=/your source/$wdate
destination=/yourdestination
log_dir=/loglocations/log
log=$log_dir/logfilename_$wdate1.log
while true
do
  if [ -d "$source" ]
  then
echo $source
echo $source/*.csv
      if [ ! -s "$source/*.csv"  ]
      then
         echo " File exists- copying the File to destination @$logdate" >> $log
         cp  $source/*.csv $destination/logfilename_$wdate1.csv
         echo " copied the file..exiting now  $logdate" >>$log
         exit 0
      else
   echo "sleepping ..."
          sleep 10
      fi
  fi
echo $wdate
done

3. find files within directories



find . -type f -exec grep -il "hello" {} \;

or if you know the file type

find . -type f -name "*.ext" -exec grep -il "hello" {} \


4. find number of cpu

On Solaris
psrinfo -v
or
/usr/platform/sun4u/sbin/prtdiag -v

5. use truss to find the process execution


$ truss -aefo logfile
$ truss -rall -wall -p

make sure the logfile is stored where enough size is available.

6. UNIX prstat vs top

While digging for problems in UNIX prstat comes handy in looking at the some of the statistics of the server.

prstat - report active process statistics

example:

Now
statistics are sorted by cpu high -low
prstat -s cpu
or -u for a particular user
prstat -u oracle -s cpu

or top 5 cpu events
prstat -s cpu -n 5

or
prstat -T (total)
Other options available to prstat are:

  -a    Report information about processes and users
-T Report information about processes and tasks.
  -u    Report only processes whose effective user  ID
  -v    Report  verbose  process  usage

  -s key            Sort output lines (that is, processes, lwps, or users)            by  key  in descending order. Only one key can be used            as an argument.             There are five possible key values:             cpu   Sort by process CPU usage. This is the default.             pri   Sort by process priority.             rss   Sort by resident set size.             size  Sort by size of process image.
-n ntop[,nbottom] (comes with ntop or nbottom)

7. Unix memory leak issues.

If several crashes occur that have an associated large core file, then this is a good indication of a potential memory leak.


At any stage if you want to generate the core dump of an active process:

On Solaris:
-0 option is to manually give the path and filename for the core dump
gcore -o /obishared/obiqb/Lognode2/core.19199 19199
gcore: /obishared/obiqb/Lognode2/core.19199.19199 dumped




Start collecting memory consumption statistics.
Solaris

The prstat command can be used to gather basic performance data to help identify if there are any processes consuming a large amount

of memory. For example, the data below is sorted by the SIZE column. SIZE is the total virtual memory size of the process:

prstat -s size


AIX

The ps command can be used to show basic memory usage per process. For example, the data below is sorted by the VSZ column, the total

virtual memory size of the process in KB:

ps -efo "vsz,pid,user,cpu,thcount,comm" | sort –n


HP-UX

The top command can be used to show basic memory usage per process. For example, the SIZE column is the total virtual memory size of

the process in KB:

top

Linux

The ps command can be used to show basic memory usage per process. For example, the data below shows the memory being used by all the

siebmtshmw proceses in KB:


ps axo user,pid,vsz,thcount,cmd | grep siebmtshmw






If you are experiencing some of the symptoms described above or if you suspect a memory leak, it is particularly important that

performance data is captured so the memory leak can be confirmed. It is important to gather at least the following pieces of

information:


Process ID (PID)
Size of the process
The executing command
The timestamp information showing exactly when the data was captured.


One method of capturing this data is to use a shell script. The following are examples of shell scripts that can be used for the

various OS types:

Solaris

while true
do
for pid in `cat pids`
do var=`date|cut -d' ' -f4`
echo "$var :\c" >> ps.log.$pid
ps -eo pid,vsz,rss,pcpu,args | grep $pid |grep -v grep >> ps.log.$pid
done
sleep 30
done

AIX

while true
do
for pid in `cat pids`
do var=`date|cut -d' ' -f4`
echo "$var :\c" >> ps.log.$pid
ps -efo "pid,vsz,user,cpu,thcount,comm" | grep $pid |grep -v grep >> ps.log.$pid
done
sleep 30
done

HP-UX

while true
do
for pid in `cat pids`
do var=`date|cut -d' ' -f4`
echo "$var :\c" >> ps.log.$pid
ps -elf | grep $pid >> ps.log.$pid
done
sleep 30
done


Linux


while true
do
for pid in `cat pids`
do var=`date|cut -d' ' -f4`
echo "$var :\c" >> ps.log.$pid
ps axo pid,vsz,user,%cpu,thcount,cmd | grep $pid |grep -v grep >> ps.log.$pid
done
sleep 30
done


above are snippets from MOS.
References:

Note 477520.1 "How To Troubleshoot Siebel Server Component Crashes on UNIX". It is however possible for a process to crash as a result of a memory leak.
Note 477004.1 "How Can Users Prevent Core Files from Being Overwritten on UNIX Platforms?"

No comments:

Post a Comment