Summary of common shell script commands for later use.

Source: Internet
Author: User
#!/bin/sh#for exm to test# ./check.sh 12 36 25 12 453 1 2 3  RETVAL=0SRRVER_START=1SRRVER_STOP=2DNS_STATUS=1dnsCheck(){        while     test "x`pidof  dnsmasq`" != x ;  do                echo "check  DNS status...................."                sleep 1                break        done}globaCheckFun(){         while true  ;  do                 dnsCheck                 echo "check  true"                 sleep  1         done}if [ -n "`ps|grep -v "grep"|grep ppp*`" ]; then echo "this string is not empty"elseecho "empty"fi#################################################################tmpdir=/tmppppoeId=$tmpdir/ppp0.pidecho  $pppoeIdif [ -f $pppoeId ] ;then    echo "is a file and exist"elseecho "not a file"fiif test "x`pidof  "$1"`" != x; thenecho "dnsmasq is running"elseecho "dnsmasq is stoped"ficase "$1" in        dns)        # do your work        echo "$1"        ;;        pppoe)         echo "$1"         ;;esac#################################################################echo "$@"echo "$*"start=`date +%s`sum=0       for par in "$@"do#  sum=$(( $par + $sum ))sum=$[$par + $sum ]echo $sumdone        endtime=`date +%s`usedtime=$(( endtime -start ))echo "usedtime:$usedtime"echo "parameter num: $#"for par in "$*"           doecho $pardone#ls  sdlfsldkl  2>error#make BOARD_TYPE=db12x BUILD_TYPE=jffs2 BUILD_CONFIG=_ap123  >uboot_mainline.txt 2>&1echo `date +%Y-%m-%d-%T`curretdate=$(date +%Y-%m-%d-%T)echo $curretdate#################################################################if [ $? -eq 0 ];  thenecho "cmd execute ok"elseecho " cnd executed failed"filine="a;b;c;d;e;f;h;j;k"oldifs=$IFSIFS=";"for itme in $line doecho  -en "$itme\t"doneecho IFS=$oldifs#################################################################va=10if [ $va -eq 11 ];  thenecho "equel ="elif  [ $va -gt 10 ];  thenecho " >"elif  [ $va -lt 10 ];  thenecho " <"elif  [ $va -ge 10 ];  thenecho " >="elif  [ $va -le 10 ];  thenecho " <="elseecho " other"fi#!/bin/shif [ "$1" = "" ] ;thenecho " usage./parse_wifi_vap.sh vap/wifiN  parse_file  "exit 0fiparse_wifi_vap(){    iwconfigcmd="essid;mode;freq;channel;bit;rate;enc;key;power;nickname;nwid;ap;txpower;sens;retry;rts;frag;modulation;commit"     line=""    start=0;    cmd=""    value=0    temp=""    while read -r line ;do    if [ "$start" = 0 ];then    if [ "$line" = "<"$1 ];then    start=1    continue    fi  elif [ "$start" = 1 ];then    if [ "$line" = $1">" ];then    start=0    break    fi      parameter=`echo $line | cut -d "=" -f 1`      value=`echo $line | cut -d "=" -f 2`      temp=`echo "$iwconfigcmd"|grep "$parameter"`      if [ -n "$temp" ];then#   `iwconfig $1 $parameter $value`   cmd="iwconfig"        else#   `iwpriv   $1 $parameter $value`   cmd="iwpriv"      fi      `$cmd $1 $parameter $value`      echo "cmd:\"$cmd $1 $parameter $value \" exeResult:$?"    fi    done < $2}WMMFILE=wireless_wmm.conf# # ath0  AC  wmm/acm/aifsn/cwmax/cwmax/noackpolicy/txoplimit value#iwpriv athN acm AC Mode value# iwpriv ath0 aifs 0 0 3# iwpriv ath0 get_aifs 0 0 1# ath0      get_aifs:3 parse_wmm(){        start=0        start1=0        tmp=0value=0        linenum=0;        while read -r line ;do                linenum=$(($linenum+1))                if [ "$start" = 0 ];then                        if [ "$line" = "<_$1_" ];then                                start=1                                continue                        fi              elif [ "$start" = 1 ];then                        if [ "$line" = "_$1_>" ];then                                start=0                                break                        fi                        tempstr=`echo $line | grep "$2"`                        if [ "$tempstr"  = "<""$2" ] ;then#                                 echo "start_line:" $1 $2 $line" "                                  start1=1                        fi                        if [ "$start1" = 1 ];then                            if [ "$tempstr" = "$2"">" ] ;then                                    start1=0                                    echo "error:not find $1 $3 in $WMMFILE"                                    break;                            fi                            tmp=`echo $line | cut -d "=" -f 1`                            tempstr=`echo $3 | cut -d "=" -f 1`                            if [ "$tmp" = "$tempstr" ];then  value=`echo $line | cut -d "=" -f 2`  echo "iwpirv $1 $3 "AC_$2" 0 $value"                                break;                            fi                        fi                fi        done < $WMMFILE# cat $WMMFILE}parse_wmm_file(){dev=$1AC=$2element=while [ $# -gt 0 ];do#  echo "\$#=$#  $@"element=$3if [ "$element" = "" ];then                        break                else    parse_wmm $dev $AC $element                    shiftfidone}#parse_wifi_vap $@parse_wmm_file $@
echo "$0 vap0 -q BK cwmax=1000"
mkwmmconf(){# echo "parameter:$@"if test -e $WMMFILE;thentmp=`cat $WMMFILE | grep "##conf"`if [ "$tmp" = "" ];thenrm -rf $WMMFILEfifiif ! test -e $WMMFILE ; thenecho "##conf" > $WMMFILEfitmp=`cat $WMMFILE | grep "<_$1_"`if [ "$tmp" = "" ];then        sed -i '/##end/d'  $WMMFILEecho "----------------------add new :$1---------------------------"echo "<_$1_" >> $WMMFILEecho "<BE" >> $WMMFILEecho "BE>" >> $WMMFILEecho "<BK" >> $WMMFILEecho "BK>" >> $WMMFILEecho "<VI" >> $WMMFILEecho "VI>" >> $WMMFILEecho "<VO" >> $WMMFILEecho "VO>" >> $WMMFILEecho "_$1_>" >> $WMMFILE# cat "$WMMFILE"fitmp=`cat $WMMFILE | grep "##end"`if [ "$tmp" = "" ];thenecho "##end" >> $WMMFILEfi#echo "*****************************************************************************************"#cat $WMMFILE#echo "*****************************************************************************************"start=0start1=0tmp=0linenum=0;while read -r line ;dolinenum=$(($linenum+1))if [ "$start" = 0 ];thenif [ "$line" = "<_$1_" ];thenstart=1continuefi      elif [ "$start" = 1 ];thenif [ "$line" = "_$1_>" ];thenstart=0echo "end line:"$line"  $1"breakfitempstr=`echo $line | grep "$2"`if [ "$tempstr"  = "<""$2" ] ;then#     echo "start_line:" $1 $2 $line" "  start1=1        fiif [ "$start1" = 1 ];then    if [ "$tempstr" = "$2"">" ] ;then    start1=0#        echo " end_line:"$line"  $1 $3"#     sed -i '/'"$line"'/i\'"$3" $WMMFILE // this cmd will add $3 to $line in all file    sed -i  $linenum'i\'"$3" $WMMFILE    echo "insert new element:$1 $3 before line:$linenum to $WMMFILE"    break;    fi    tmp=`echo $line | cut -d "=" -f 1`    tempstr=`echo $3 | cut -d "=" -f 1`    if [ "$tmp" = "$tempstr" ];thentmp=`echo $line | cut -d "=" -f 2`tempstr=`echo $3 | cut -d "=" -f 2`if [ "$tmp" != "$tempstr" ];then  sed -i  "$linenum"d $WMMFILE  sed -i  $linenum'i\'"$3" $WMMFILE  echo "replace $1 $2: $line to $3 $WMMFILE "   fibreak;    fififidone < $WMMFILE# cat $WMMFILE}
Scripts used at work:

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.