Not long ago, interns, now in the group to help dalao s run Case, from time to time to collect a wood Dump, every time the command is too annoying, so forced to learn to write their own Shell scripts. It was really painful at first, and I couldn't get any books. I could only draw pictures with half-truthful and half-truthful information on the internet. Say less nonsense, go to the text!
========================= I am the dividing line.=========================
1 clear 2 3 echo "Check_dump is a tool help you check dumps" 4 5 numberOfSPs=2 6 commands="-lcd" 17 ########################################################### 18 # 19 # getopts The order is Korn/POSIX shell Built-in commands 20 # ,Used to retrieve options and option parameters from the parameter list. Options are made by one+(Plus sign 21 # Or by one-(The minus sign) begins with a character. One is neither with+,Either 22 # In order to-The start option ends the option string. Each call getopts When commanded, it 23 # Place the value of the next option in Name and index the next parameter to be processed 24 # Place it in the shell variable OPTIND. Whenever the shell is called, the 25 # OPTIND Initialization for 1. When the options are + At the beginning, we will + Pre 26 # Values appended to Name. 27 # 28 ########################################################## 29 30 while getopts ":a:b:c:n:" opt # If the character in the option string is followed by a ":" (colon), then this option is expected to have parameters. 31 # Ad locum a Whether there is a colon ahead or not will determine the following*/?Can it work? 32 # Detailed instructions are available for reference. https://www.ibm.com/support/knowledgecenter/zh/ssw_aix_71/com.ibm.aix.cmds2/getopts.htm 33 do 34 case $opt in 35 a) 36 d1=$OPTARG # When an item needs an option parameter, the getopts command places it in the variable OPTARG 37 echo "d1 is $d1 " 38 ;; # You have to remember to add the end; it's equivalent to break in other languages. 39 b) 40 d2=$OPTARG # OPTARG appears, and that's where we get the parameters. 41 echo "d2 is $d2, and destination is $d1.$d2" # The variables in the Shell are interesting, so you can write them directly and output them along the way. 42 ;; # Double quotation marks resolve escaped characters and variable names in strings, but single quotation marks do not. 43 c) 44 commands=$OPTARG 45 echo " Addtional command: $commands " 46 ;; 47 n) 48 numberOfSPs=$OPTARG 49 echo "Number of SPs has changed to $numberOfSPs " 50 ;; 51 *) # * perhaps ? Match all things that are not listed above 52 echo "Usage: check_dump -a<xxx.xxx.xxx> -b<xxx> -c<commands> -n<number of SP> 53 And the destination is IP for Unisphere." 54 exit 55 esac 56 done 57 58 i=1 59 while [ $i -le $numberOfSPs ] 60 do 61 d2=$((d2+1)) 62 destination="$d1.$d2" 63 echo "============================================= 64 checking SP$i, destination is :$destination" # It's interesting to change lines directly in the string, and print out content will also change lines! 65 i=$((i+1)) # The $(()) is the same as the ``below', which means that the inside can be executed and other operations need to be performed later. 66 res="`ssh $destination svc_dc $commands`" 67 if [[ ${#res} == 234 ]];then # Compare the abbreviated version of "expr instructions" which should be studied in depth. Some of the original instructions are few but not very good. 68 # notice if What's behind it?!!!";then""Five characters a must! 69 echo "No dumps" 70 else # If there are more branches, you can choose to use them. elif[[ condition ]];then 71 echo "Found dumps: 72 $res" 73 fi 74 75 done 76 exit
That's it. Just drop something on it when you think about it.