全部博文(2005)
分类:
2008-12-28 12:08:33
# Copyright 2008 luther.gliethttp #============================================================================ lu_list_commands='' lu_drain_commands() { # cmds=$1 # echo $cmds # echo `expr index "$cmds" ';'` return 0 } lu_laping() { # echo $@ shift local maxcounts=$1 local sleep_seconds=$2 local pingcounts=$3 local interval=$4 local ip_addr=$5 while [ $maxcounts -gt 0 ]; do ping -c $pingcounts $ip_addr -i $interval >/dev/null 2>&1 if [ $? -gt 0 ]; then echo 'wrong' else echo 'pass' fi sleep $sleep_seconds maxcounts=`expr $maxcounts - 1` done } Usage() { # cat <<\_EOF cat <<_EOF Usage: `basename $0` -t[loop seconds] cmd0 cmd1 ... -a[maxcounts],[sleep_seconds],[pingcounts],[interval],[ip_addr] commands list: _EOF echo return 0 } while getopts hva: op; do case $op in 'h') Usage exit 0 ;; 't') LU_SECONDS=$OPTARG echo $LU_SECONDS | grep -q '[^0-9]' && Usage && exit 1 [ $LU_SECONDS -eq 0 ] && LU_SECONDS=$((0xffffffff)) ;; 'a') [ -z $lapingindex ] && lapingindex=0 substring=$OPTARG # echo `expr index "$substring" ','` substring=`echo $substring | tr ',' ' '` # ${substring//','/' '} if [ $lapingindex -ne 0 ]; then lu_list_commands=$lu_list_commands';' fi lu_list_commands=$lu_list_commands"lu_laping"' '"$lapingindex"' '"$substring" lapingindex=`expr $lapingindex + 1` echo '===========================================' echo "$substring" lu_laping $lapingindex $substring ;; *) ;; esac done # echo $lu_list_commands # ($lu_list_commands) # (lu_laping 0 2 1 1 1 127.0.0.1;lu_laping 0 2 1 1 1 127.0.0.1) lu_drain_commands "$lu_list_commands" |