A few simple shell scripts to draw

Source: Internet
Author: User
Tags md5

First timed crawl server JVM related information

#! /bin/sh
    
#get_current_time
export java_home=/opt/jdk1.6.0_10/
export path= $JAVA _home/bin: $PATH
Export classpath=.: $JAVA _home/lib/tools.jar: $JAVA _home/lib/dt.jar: $CLASSPATH
    
date= ' Date +%y-%m-%d-%h:%m:%s ' "
    
root="/data/dxm/"
    
    
jmapends= $Root $date" _jmap.txt "jstackends=
$Root $date
" _jstack.txt " jstateends= $Root $date "_jstate.txt"
    
    
    
    
    
#start to register the JMAP message
echo "Start to register the Jmap to" $jmap Ends
jmap-histo:live ' jps|grep Resin |awk ' nr==1 ' |awk ' {print $} ' > $jmapends sleep
    
2
    
#start to Regis ter the Jtack message
echo "Start to register the Jstack to" $jstackends the
jstack-l ' jps|grep Resin |awk ' nr==1 ' | awk ' {print} ' > $jstackends sleep
    
2 #start to
    
Register the jstate message
echo ' start to register th E jstate message to "$jstateends
jstat-gcutil-t-h20 ' jps|grep Resin |awk ' nr==1 ' |awk ' {print $} '  1000 T $jstateends

This can run a timer:

Crontab-e

*/10 * * * * sh/timer/timer.sh #每十分钟抓一次

Second script: Improve the script above to print JVM information only after the system load reaches the specified value

Java Code #! /bin/sh      Function printjvmmessage () {    #get_current_time   Export java_home=/opt/ jdk1.6.0_10/  Export path= $JAVA _home/bin: $PATH   export classpath=.: $JAVA _home/lib/tools.jar: $JAVA _home/ Lib/dt.jar: $CLASSPATH     #only the system load greate than 1*8pu then start to print the GC details      date= ' Date "+%y-%m-%d-%h:%m:%s" '     root= "/data/dxm/"       jmapends= $Root $date "_ Jmap.txt "  jstackends= $Root $date" _jstack.txt "  jstateends= $Root $date" _jstate.txt "      Start to register the Jmap message  echo "Start to register the Jmap to" $jmapends   jmap-histo:live ' Jps|grep R Esin |awk ' nr==1 ' |awk ' {print} ' > $jmapends     sleep 2    #start to register the Jtack message& nbsp echo "Start to register" Jstack to "$jstackends   jstack-l ' jps|grep Resin |awk ' nr==1 ' |awk ' {print} ' > $js tackends    Sleep 2  &nbsP #start to register the Jstate message  echo ' start to register ' jstate message to ' $jstateends   Jstat-gcutil -t-h20 ' jps|grep Resin |awk ' nr==1 ' |awk ' {print $} '   1000 > $jstateends    }      #System Max Load per Cpu,when The systemload reached the max_load * Cpu_number then start register the JVM message  M ax_load=1    cpu_number= ' Cat/proc/cpuinfo | grep processor |wc-l '     <strong style= ' Background-color:rgb (255, 255, 255); " ><span style= "Color:rgb (255, 0, 0);" >total_load_to_warn</span></strong>=$ (($MAX _load* $CPU _number))   #TOTAL_LOAD_TO_WARN =1    current_system_load= ' uptime | awk ' {print $ (NF-2)} ' | Sed ' s/,//'     start_time= ' date ' +%y-%m-%d-%h:%m:%s '     echo ' Start to print the JVM Message...curre Nttime is: ' $Start _time  echo ' current system load are ' $CURRENT _system_load ' and Totao_load_to_warn is ' $TOTAL _load_ to_warn    IF [$(echo "$CURRENT _system_load > $TOTAL _load_to_warn" |bc) = = 1]; then      Echo ' printint the JVM message ... '       printjvmmessage  fi     finish_time= ' date ' +%y-%m-%d-%h:%m:%s '   echo ' Finish to print the JVM Message...and ' $ finish_time 

#! /bin/sh function Printjvmmessage () {#get_current_time export java_home=/opt/jdk1.6.0_10/export path= $JAVA _home/bin:$ PATH export classpath=.: $JAVA _home/lib/tools.jar: $JAVA _home/lib/dt.jar: $CLASSPATH #only The system load greate than 1* 8PU then start to print the GC details date= ' date ' +%y-%m-%d-%h:%m:%s ' root= '/data/dxm/' jmapends= $Root $date ' _jmap.t XT "Jstackends= $Root $date" _jstack.txt "jstateends= $Root $date" _jstate.txt "#start to register the JMAP message echo" star  T to register the Jmap to "$jmapends jmap-histo:live ' jps|grep Resin |awk ' nr==1 ' |awk ' {print} ' > $jmapends sleep  2 #start to register the Jtack message echo "Start to register the jstack to" $jstackends jstack-l ' Jps|grep Resin |awk ' Nr==1 ' |awk ' {print '} ' > $jstackends sleep 2 #start to register the jstate message echo "Start to register the JS Tate message to "$jstateends jstat-gcutil-t-h20 ' jps|grep Resin |awk ' nr==1 ' |awk ' {print $} ' 1000 > $jstateend s} #System Max Load PEr cpu,when the systemload reached the max_load * Cpu_number then start register the JVM message max_load=1 cpu_number= ' C At/proc/cpuinfo |

 grep processor |wc-l 'Total_load_to_warn=$ (($MAX _load* $CPU _number)) #TOTAL_LOAD_TO_WARN =1 current_system_load= ' uptime | awk ' {print $ (NF-2)} ' | Sed ' s/,//' start_time= ' date ' +%y-%m-%d-%h:%m:%s ' ' echo ' Start to print the JVM Message...currenttime is: ' $Start _time E Cho ' current system load are ' $CURRENT _system_load ' and Totao_load_to_warn is ' $TOTAL _load_to_warn if [$ (Echo $CURRENT _sy Stem_load > $TOTAL _load_to_warn "|bc) = = 1]; Then Echo ' Printint the JVM message ... ' printjvmmessage fi finish_time= ' date ' +%y-%m-%d-%h:%m:%s ' ' echo ' Finish to Prin t the JVM Message...and current time is: ' $Finish _time

Third script: Compare two versions for the same jar package (with changes):

#! /bin/sh #compare The Lib files ' s MD5 int file1 with those in file2 #if it to exist in File1 or one lib file ' s MD5 
    
Is isn't equal I #with the other then print it to the Log.txt libpath1=$1 libpath2=$2 date= ' Date ' +%y-%m-%d-%h:%m:%s ' log= $date "_log.txt" echo "-----------log File" $LOG echo LibPath1: $LibPath 1 echo LibPath2: $LibPath 2 echo Li BPath1: $LibPath 1 \ >> $LOG echo LibPath2: $LibPath 2 \ >> $LOG echo >> $LOG echo >> $LOG fo
R File in ' ls-f $LibPath 1|grep jar '; Do md5= ' md5sum $1$file |awk ' nr==1 ' |awk ' {print} ' file2= $LibPath 2$file #echo ' File2-----------------' $File 2 #if The same LIB file exist if [! f "$File 2"]; Then echo $File exist LibPath1 echo $File only exist LibPath1 \ r >> $LOG echo >
        > $LOG #if The same file exist in Directory2 else md52= ' md5sum $File 2 |awk ' nr==1 ' {print $} ' If ["$MD 5"!= "$MD 52"];
   Then             echo the $File changed \ r >> $LOG echo >> $LOG echo the $File ch Anged fi fi Done
The file on the
md5compare.sh
Running is possible with the following command:
./md5compare.sh  Libpath1 libpath2
Note Libpath1,libpath2 must end with "/" such as:
/opt/root_2011-09-08-09:57:26/web-inf/lib/
Instead of
/opt/root_2011-09-08-09:57:26/web-inf/lib]]]
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.