3-column array, ARRAYA,ARRAYB,ARRAYC;
Each one by one corresponds to the number of resources that the host and its hosts can create, and ARRAYC indicates the number of resources that need to be created;
Arraya= ("192.168.1.1" "192.168.1.2" "192.168.1.3" "192.168.1.4")
arrayb= ("1" "2" "1" "2")
arrayc= ("100" "200" "300" "400" "500" "600" "700")
Note that the previous situation ${#arrayC [@}}=7, which exceeds the arrayb of all the resources that can be created 1+2+1+2=6,
When you need to create a resource 700, the script automatically exits;
There are 2 workarounds, the first forward double for loop, from the first element round to the last element,
However, this method is inefficient, followed by the second method, the code also write less than dozens of lines;
For _host in ${array[a]};d o j=${arrayb[0]}    FOR _RES IN ${ARRAY[C]};d o ssh ${_host} init [[ $? == 0 ]] && { ((j=j-1));echo "Success"; } | | { echo "Fail"; exit 1; } arrayc= (${array[@]:1}) if [[ ${j} == "0" ]];then [[ ${#arrayC [@]} == "0" ]] && status=0 | | { STATUS=1;break; } esle [[ ${#arrayC [@]} == "0" ]] && status=0 fi done if [[ "${status}" == "1" ]];then arraya= (${arraya[@]:1}) arrayb= (${arrayb[@]:1}) if [[ ${#array [@]} == "0" ]];then [[ "${#arrayC [@]}" != "0" ]] && { echo "limited resources, ${arrayc[@]} refused to create";exit 1; } esle continue fi else { echo " Initialized as required "; EXIT 0; }  &NBsp; fidone
This article is from the "Ithandonglin" blog, make sure to keep this source http://ithandonglin.blog.51cto.com/12414114/1886176
Code sharing:-Using array assignment to implement while and shift functions