歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

腳本范例

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

張總

[root@www ~]# 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

夏玉龍

[root@localhost 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

高手

[root@localhost 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

小王

[root@station99 ~]# 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

張總

[root@pxe38 ~]# 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

[root@station99 bin]# cat sumwhile.sh

#!/bin/bash

sum=0

id=1

while [ $id -le 100 ]

do

let sum+=id

let id++

done

echo sum=$sum

[root@station99 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

本文出自 “博客作業初版” 博客,謝絕轉載!

Copyright © Linux教程網 All Rights Reserved