GoldenGate process count script


#!/bin/bash

###############################
# determine the OS type
###############################
OSNAME=`uname`

case "$OSNAME" in
"SunOS")
echo "OSNAME = $OSNAME"
    ;;
Linux")
echo "OSNAME = $OSNAME"
    ;;
  "*")
    echo "This script has not been verified on $OSNAME"
    exit 1
    ;;
esac
<div class="line number20 index19 alt1"></div>
<div class="line number21 index20 alt2">###############################</code></div>
<div class="line number22 index21 alt1"><code class="plain plain"># set the temp file</code></div>
<div class="line number23 index22 alt2"><code class="plain plain">###############################</code></div>
<div class="line number24 index23 alt1"><code class="plain plain">TMPFILE=/tmp/pmem.tmp</code></div>
<div class="line number25 index24 alt2"><code class="plain plain">if [ -f $TMPFILE ]</code></div>
<div class="line number26 index25 alt1"><code class="plain plain">then</code></div>
<div class="line number27 index26 alt2"><code class="plain spaces">  </code><code class="plain plain">rm -f $TMPFILE</code></div>
<div class="line number28 index27 alt1"><code class="plain plain">fi</code></div>
<div class="line number29 index28 alt2"></div>
<div class="line number30 index29 alt1"><code class="plain plain">################################</code></div>
<div class="line number31 index30 alt2"><code class="plain plain"># loop over the gg process types</code></div>
<div class="line number32 index31 alt1"><code class="plain plain">################################</code></div>
<div class="line number33 index32 alt2"><code class="plain plain">PROCESSES="extract replicat"</code></div>
<div class="line number34 index33 alt1"></div>
<div class="line number35 index34 alt2"><code class="plain plain">for PROCESS in $PROCESSES</code></div>
<div class="line number36 index35 alt1"><code class="plain plain">do</code></div>
<div class="line number37 index36 alt2"><code class="plain spaces">  </code><code class="plain plain">FLAG=""</code></div>
<div class="line number38 index37 alt1"><code class="plain spaces">  </code><code class="plain plain">FLAG=`ps -ef | grep $PROCESS`</code></div>
<div class="line number39 index38 alt2"><code class="plain spaces">  </code><code class="plain plain">if [ -z "FLAG" ]</code></div>
<div class="line number40 index39 alt1"><code class="plain spaces">  </code><code class="plain plain">then</code></div>
<div class="line number41 index40 alt2"><code class="plain spaces">    </code><code class="plain plain">echo "No $PROCESS processes found"</code></div>
<div class="line number42 index41 alt1"><code class="plain spaces">  </code><code class="plain plain">else</code></div>
<div class="line number43 index42 alt2"><code class="plain spaces">    </code><code class="plain plain">echo</code></div>
<div class="line number44 index43 alt1"><code class="plain spaces">    </code><code class="plain plain">echo "#####################################"</code></div>
<div class="line number45 index44 alt2"><code class="plain spaces">    </code><code class="plain plain">echo "# Individual $PROCESS Process Usage #"</code></div>
<div class="line number46 index45 alt1"><code class="plain spaces">    </code><code class="plain plain">echo "#####################################"</code></div>
<div class="line number47 index46 alt2"><code class="plain spaces">    </code><code class="plain plain">case "$OSNAME" in</code></div>
<div class="line number48 index47 alt1"><code class="plain spaces">      </code><code class="plain plain">"Linux")</code></div>
<div class="line number49 index48 alt2"><code class="plain spaces">        </code><code class="plain plain">ps -C $PROCESS -O rss > $TMPFILE</code></div>
<div class="line number50 index49 alt1"><code class="plain spaces">        </code><code class="plain plain">cat $TMPFILE | grep $PROCESS | awk '{print $2/1024, "MB", $12}' | sort -k 2</code></div>
<div class="line number51 index50 alt2"><code class="plain spaces">        </code><code class="plain plain">;;</code></div>
<div class="line number52 index51 alt1"><code class="plain spaces">      </code><code class="plain plain">"SunOS")</code></div>
<div class="line number53 index52 alt2"><code class="plain spaces">        </code><code class="plain plain">ps -efo vsz,uid,pid,ppid,pcpu,args | grep -v grep | grep $PROCESS > $TMPFILE</code></div>
<div class="line number54 index53 alt1"><code class="plain spaces">        </code><code class="plain plain">cat $TMPFILE | grep $PROCESS | awk '{print $1/1024, "MB", $8}' | sort -k 2</code></div>
<div class="line number55 index54 alt2"><code class="plain spaces">        </code><code class="plain plain">;;</code></div>
<div class="line number56 index55 alt1"><code class="plain spaces">      </code><code class="plain plain">"*")</code></div>
<div class="line number57 index56 alt2"><code class="plain spaces">        </code><code class="plain plain">echo "This script has not been verified on $OSNAME"</code></div>
<div class="line number58 index57 alt1"><code class="plain spaces">        </code><code class="plain plain">exit 1</code></div>
<div class="line number59 index58 alt2"><code class="plain spaces">        </code><code class="plain plain">;;</code></div>
<div class="line number60 index59 alt1"><code class="plain spaces">    </code><code class="plain plain">esac</code></div>
<div class="line number61 index60 alt2"><code class="plain spaces">    </code><code class="plain plain">rm -f $TMPFILE</code></div>
<div class="line number62 index61 alt1"></div>
<div class="line number63 index62 alt2"><code class="plain spaces">    </code><code class="plain plain">echo</code></div>
echo "#####################################"</code></div>
echo "#   Total $PROCESS Process Usage    #"</code></div>
echo "#####################################"</code></div>
<div class="line number67 index66 alt2"><code class="plain spaces">    </code><code class="plain plain">case "$OSNAME" in</code></div>
<div class="line number68 index67 alt1"><code class="plain spaces">      </code><code class="plain plain">"Linux")</code></div>
<div class="line number69 index68 alt2"><code class="plain spaces">        </code><code class="plain plain">ps -C $PROCESS -O rss > $TMPFILE</code></div>
<div class="line number70 index69 alt1"><code class="plain spaces">        </code><code class="plain plain">cat $TMPFILE | grep $PROCESS | awk '{count ++; sum=sum+$2; } END \</code></div>
<div class="line number71 index70 alt2"><code class="plain spaces">          </code><code class="plain plain">{ print "Number of processes      =",count; \</code></div>
<div class="line number72 index71 alt1"><code class="plain spaces">          </code><code class="plain plain">print "AVG Memory usage/process =",sum/1024/count, "MB"; \</code></div>
<div class="line number73 index72 alt2"><code class="plain spaces">          </code><code class="plain plain">print "Total memory usage       =", sum/1024,  " MB"}'</code></div>
<div class="line number74 index73 alt1"><code class="plain spaces">        </code><code class="plain plain">;;</code></div>
<div class="line number75 index74 alt2"><code class="plain spaces">      </code><code class="plain plain">"SunOS")</code></div>
<div class="line number76 index75 alt1"><code class="plain spaces">        </code><code class="plain plain">ps -efo vsz,uid,pid,ppid,pcpu,comm | grep -v grep | grep $PROCESS > $TMPFILE</code></div>
<div class="line number77 index76 alt2"><code class="plain spaces">        </code><code class="plain plain">cat $TMPFILE | awk '{count ++; sum=sum+$1; } END \</code></div>
<div class="line number78 index77 alt1"><code class="plain spaces">          </code><code class="plain plain">{ print "Number of processes      =",count; \</code></div>
<div class="line number79 index78 alt2"><code class="plain spaces">          </code><code class="plain plain">print "AVG Memory usage/process =",sum/1024/count, "MB"; \</code></div>
<div class="line number80 index79 alt1"><code class="plain spaces">          </code><code class="plain plain">print "Total memory usage       =", sum/1024,  " MB"}'</code></div>
<div class="line number81 index80 alt2"><code class="plain spaces">        </code><code class="plain plain">;;</code></div>
<div class="line number82 index81 alt1"><code class="plain spaces">      </code><code class="plain plain">"*")</code></div>
<div class="line number83 index82 alt2"><code class="plain spaces">        </code><code class="plain plain">echo "This script has not been verified on $OSNAME"</code></div>
<div class="line number84 index83 alt1"><code class="plain spaces">        </code><code class="plain plain">exit 1</code></div>
<div class="line number85 index84 alt2"><code class="plain spaces">        </code><code class="plain plain">;;</code></div>
<div class="line number86 index85 alt1"><code class="plain spaces">    </code><code class="plain plain">esac</code></div>
<div class="line number87 index86 alt2"><code class="plain spaces">    </code><code class="plain plain">rm -f $TMPFILE</code></div>
  fi
done

exit 0

 

Leave a Reply

Your email address will not be published. Required fields are marked *