Skip to content

Commit ec3a145

Browse files
committed
add func for limit host to run when limit num less then all hosts.
1 parent 8788ef7 commit ec3a145

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

bashrc/threads.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CURDIR=$(cd "$(dirname "$0")"; pwd);
1111
g_HOST_LIST=$1
1212
g_THREAD_NUM=300
1313
g_PORT=22
14+
g_LIMIT=0
1415
TMPFILE="pipe.$$"
1516
SSH="ssh -n -o PasswordAuthentication=no -o StrictHostKeyChecking=no -o ConnectTimeout=5 "
1617
SCP='scp -q -r -o PasswordAuthentication=no -o StrictHostKeyChecking=no -o ConnectTimeout=5 '
@@ -46,6 +47,7 @@ Options:
4647
-c, --concurrent num Thread Nummber for run the command at same time, default: 1.
4748
-s, --ssh Use ssh authorized_keys to login without password query from DB.
4849
-p, --port Use port instead of defult port:22.
50+
-l, --limit Limit num for host to run when limit less then all host num.
4951
-h, --help Print this help infomation.
5052
5153
Require:
@@ -81,6 +83,10 @@ _parse_options()
8183
g_PORT=${2}
8284
shift 2
8385
;;
86+
-l|--limit)
87+
g_LIMIT=${2}
88+
shift 2
89+
;;
8490
-h|--help)
8591
usage
8692
exit
@@ -163,6 +169,13 @@ do
163169
fi
164170
unset fchar
165171

172+
if [ "x$g_LIMIT" != "x0" ]; then
173+
if [ "$g_LIMIT" -le "$INDEX" ]; then
174+
_trace "Reach limit num of $g_LIMIT"
175+
break
176+
fi
177+
fi
178+
166179
_trace "[$INDEX] start ${HOST} ......"
167180
read <&9
168181

0 commit comments

Comments
 (0)