脚本范例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了脚本范例相关的知识,希望对你有一定的参考价值。

0-9:[0-9]

10-99:[1-9][0-9]

100-199:1[0-9][0-9]

200-249:2[0-4][0-9]

250-255:25[0-5]


0-255.X.Y.Z.

(\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]\.){3}[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]\b)




ifconfig | grep -E "(\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>.){3}\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"



#!/bin/bash

#计算UID之和

ID=`cat -n /etc/passwd|egrep  "\b($1|$2)\b[^:]"|cut -d ":" -f 3`

echo $ID

sum=$((`echo ${ID}|tr -s " " "+"`))

echo "ID$1+ID$2 = ${sum}"


ifconfig | sed -n ‘/\<inet\>/p‘ | sed -r ‘s/.*((\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-1][0-9]|22[1-3])\>(\.\<[[:digit:]]{1,3}\>){3})).*/\1/‘



ls *.rpm  | sed  ‘s/..*\.\(..*\)\.rpm/\1/‘ |sort |uniq -c



张总

[[email protected] ~]# cat /script/dengbiansanjiao.sh

#!/bin/bash

read -p "please input linenumber:" linenumber

for lineid in `seq 1 $linenumber`

do

        for a in `seq 1 $[$linenumber-$lineid]`

        do

                echo -n " "

        done

        for b in `seq 1 $[2*$lineid-1]`

        do

                echo -n "*"

        done

        echo

done


夏玉龙


[[email protected] 6_6]# cat  print_asterisk_triangle      

#!/bin/bash

read -p "the line of triangle " line


for i in `seq 1 $line`

do

        character_count=$(($line-$i+2*$i-1))

        space_count=$(($line-$i))

        for j in `seq 1 $character_count`

        do

                if [ $j -le $space_count ];then

                        echo -n " "

                else

                        echo -n "*"

                fi

        done

        echo

done



王总


#!/bin/bash

#


read -p "input a number:" input


for var1 in $(seq "$input") ;do

        for var2 in $(seq  "$input" -1 1);do

                if [ $var2 -gt $var1 ];then

                        echo -n " "

                else

                        echo -n "*"

                fi



                if [ $var1 -gt $var2 ];then

                        echo -n "*"

                fi

        done

        echo

done

echo 


高手

[[email protected] python]# cat  cfb.sh    

#!/bin/bash

i=1

while [ $i -le 9 ]

do

    j=1

    while [ $j -le 9 ]

    do

        if [ $i -ge $j ]

        then

            echo -en "$i*$j=$(($i*$j))\t"

        fi

            j=$(($j+1))

    done

    i=$(($i+1))

    printf "\n"

done



小王


[[email protected] ~]# cat bin/sum.sh 

#!/bin/bash

sum=0

for id in `seq $1`

do

        let sum+=id

done

echo sum=$sum



赵委员

#

CLASSTYPE=‘F‘

read -p "Please Input a NETWORK ADDRESS(such as 192.168.100.0): " NETADDR

if [ -z $NETADDR ] ; then

  echo -e "\033[2;31mIt must be type network address.\033[0m"

  exit 4

fi


#!/bin/bash

#

CLASSTYPE=‘F‘

read -p "Please Input a NETWORK ADDRESS(such as 192.168.100.0): " NETADDR

if [ -z $NETADDR ] ; then

  echo -e "\033[2;31mIt must be type network address.\033[0m"

  exit 4

fi


  echo -e "\033[2;31mInvalid NETWORK ADDRESS.\033[0m"

  exit 5

fi


FIRADD=`echo $NETADDR | cut -d"." -f1`

SECADD=`echo $NETADDR | cut -d"." -f2`

THIADD=`echo $NETADDR | cut -d"." -f3`


if [ $FIRADD -gt 0 -a $FIRADD -le 126 ] ; then

  CLASSTYPE=‘A‘

elif [ $FIRADD -ge 128 -a $FIRADD -le 191 ] ; then

  CLASSTYPE=‘B‘

elif [ $FIRADD -ge 192 -a $FIRADD -le 223 ] ; then

  CLASSTYPE=‘C‘

else

  echo -e "\033[2;31mInvalid NETWORK ADDRESS.\033[0m"

  exit 10

fi

echo $CLASSTYPE


case $CLASSTYPE in

  A)

    for I in `seq 0 255` ; do

      for J in `seq 0 255` ; do

        for K in `seq 0 255` ; do

          if [ $I -ne 0 -a $J -ne 0 -a $K -ne 0 ] || [ $I -ne 255 -a $J -ne 255 -a $K -ne 255 ] ; then

            if ping -c1 -W1 ${FIRADD}.$I.$J.$K &> /dev/null ; then

              echo -e "${FIRADD}.$I.$J.$K is \033[2;32mOnline\033[0m."

            else

              echo -e "${FIRADD}.$I.$J.$K is \033[2;31mOffline\033[0m."

            fi

          fi

        done

      done

    done

    ;;

  B)

    for M in `seq 0 255` ; do

      for N in `seq 0 255` ; do

        if [ $M -ne 0 -a $N -ne 0 ] || [ $M -ne 255 -a $M -ne 255 ] ; then

          if ping -c1 -W1 ${FIRADD}.${SECADD}.$M.$N &> /dev/null ; then




扫描网段


#!/bin/bash

read -p "please input the network(192.16.0.0):"  NETWORK

network=`echo $NETWORK |cut -d. -f1-3`

for id in {1..10}

do

        ping $network.$id -c1 -W1 &> /dev/null &&  echo $network.$id is up || echo $network.$id is down

done


张总

[[email protected] ~]# cat 9.sh

#!/bin/bash

for i in {1..9}

  do  

    for j in `seq $i`

        do 

           sum=$[$i*$j]

           echo -n -e "$j*$i=$sum\t"

           

        done

        echo

  done


[[email protected] bin]# cat sumwhile.sh 

#!/bin/bash

sum=0

id=1

while [ $id -le 100 ]

do

        let sum+=id

        let id++

done

echo sum=$sum



[[email protected] bin]# vi maxmin.sh  


#!/bin/bash

id=1

rand=$RANDOM

max=$rand

min=$rand

echo $rand

while [ $id -le 9 ]

do 


        rand=$RANDOM

        echo $rand

        if [ $rand -gt $max ];then

                max=$rand

        fi

        if [ $rand -lt $min ];then

                min=$rand

        fi

        let id++

done

echo max is $max

echo min is $min



本文出自 “博客作业初版” 博客,谢绝转载!

以上是关于脚本范例的主要内容,如果未能解决你的问题,请参考以下文章

python自动化运维脚本范例

sed命令使用范例

Atitit 图像处理 halcon类库的使用  范例边缘检测 attilax总结

INNO SETUP脚本向导创建的基本脚本

随堂练习 shell脚本

shell 脚本发送邮件