function ping_target()
{
local target=$1
timeout 0.5 ping $target -c 1 > /dev/null
if [ "$?" == "0" ]
then
echo "ping succ: $target" >> "$RESULT_FILE"
else
echo "ping failed: $target" >> "$RESULT_FILE"
fi
}
count_all=0
count_fail=0
count_succ=0
MAX_CONCURRENT=50
current_jobs=0
truncate -s0 "$RESULT_FILE"
while read line
do
count_all=`expr $count_all + 1`
ping_target $line &
while ((current_jobs >= MAX_CONCURRENT))
do
current_jobs=$(pstree -p $$ |wc -l)
sleep 0.1
done
done <<< "$list"
wait
count_succ=$(grep -c "succ" "$RESULT_FILE")
count_fail=$(grep -c "failed" "$RESULT_FILE")
total=$(wc -l < "$RESULT_FILE")