linux - Multithreading a Bash Script -
i'm finding difficult run script multithreaded.
i cannot fix script, not know error making, there not many examples in stack.
#!/bin/bash function teste(){ in $(seq 0 10); connect_timeout=1 # in seconds a="$1." b=$i ip_address=$a$b port="${2}" set +e data=$(curl --head -vs -m ${connect_timeout} http://${ip_address}:${port} 2>&1) exit_code="$?" data=$(echo -ne "${data}" | grep "server: ") set -e if [[ ${exit_code} -eq 0 ]]; if [[ -n "${data}" ]]; echo -ne "${ip_address} - ${data}" else echo "${ip_address} - got empty data server!" fi else echo "${ip_address} - no server." fi done } function doexecute(){ set -e if [[ $# -ne 2 ]]; echo "usage: $(basename "$0") ip_address_number port" exit 1 fi threads=10; threads=$(( $threads - 1)) thread in `seq $threads` teste ${1} & done } doexecute
your doexecute
function expects 2 arguments, else prints error message , exits (not returns). so, when call without argument exits calling shell.
Comments
Post a Comment