@@ -11,10 +11,14 @@ CURDIR=$(cd "$(dirname "$0")"; pwd);
1111g_HOST_LIST=$1
1212g_THREAD_NUM=300
1313g_PORT=22
14+ g_LIMIT=0
1415TMPFILE=" pipe.$$ "
1516SSH=" ssh -n -o PasswordAuthentication=no -o StrictHostKeyChecking=no -o ConnectTimeout=5 "
1617SCP=' scp -q -r -o PasswordAuthentication=no -o StrictHostKeyChecking=no -o ConnectTimeout=5 '
1718
19+ RET_OK=0
20+ RET_FAIL=1
21+
1822# #################### function #########################
1923_report_err () { echo " ${MYNAME} : Error: $* " >&2 ; }
2024
@@ -46,6 +50,7 @@ Options:
4650 -c, --concurrent num Thread Nummber for run the command at same time, default: 1.
4751 -s, --ssh Use ssh authorized_keys to login without password query from DB.
4852 -p, --port Use port instead of defult port:22.
53+ -l, --limit Limit num for host to run when limit less then all host num.
4954 -h, --help Print this help infomation.
5055
5156Require:
@@ -56,7 +61,7 @@ Notice:
5661 please check the result output under log/hostname.
5762USAGE
5863
59- exit 1
64+ exit $RET_OK
6065}
6166
6267#
@@ -81,6 +86,10 @@ _parse_options()
8186 g_PORT=${2}
8287 shift 2
8388 ;;
89+ -l|--limit)
90+ g_LIMIT=${2}
91+ shift 2
92+ ;;
8493 -h|--help)
8594 usage
8695 exit
@@ -103,7 +112,7 @@ _parse_options()
103112
104113 case ${# argv[@]} in
105114 2)
106- g_HOST_LIST=$( readlink -f " ${argv[0]} " )
115+ command -v greadlink > /dev/null 2>&1 && g_HOST_LIST= $( greadlink -f " ${argv[0]} " ) || g_HOST_LIST=$( readlink -f " ${argv[0]} " )
107116 g_CMD=" ${argv[1]} "
108117 ;;
109118 0|* )
@@ -148,6 +157,7 @@ INDEX=0
148157
149158while read -r HOST
150159do
160+ HOST=${HOST#* (: space: )}
151161 (( INDEX++ ))
152162 fchar=` echo ${HOST} | cut -c -1`
153163
162172 fi
163173 unset fchar
164174
175+ if [ " x$g_LIMIT " != " x0" ]; then
176+ if [ " $g_LIMIT " -lt " $INDEX " ]; then
177+ _trace " Reach limit num of $g_LIMIT "
178+ break
179+ fi
180+ fi
181+
165182 _trace " [$INDEX ] start ${HOST} ......"
166183 read < & 9
167184
168- ping -c 1 -w 3 ${HOST} & > /dev/null
185+ ping -c 1 -W 3 ${HOST} & > /dev/null
169186
170187 if [ $? -ne 0 ]; then
171188 _print_fatal " [$INDEX ] Error: ${HOST} is unreachable."
0 commit comments