如何对bash代理检查器进行多线程处理?

时间:2018-12-05 18:49:04

标签: multithreading bash curl

我在下面的bash中进行了编码,以从文本文件中检查代理服务器。

#!/bin/bash

# CURL BASED
# REQUIRES FILE NAME AS ARGUMENT


# HTTP Proxy Server's Port Number
#port=$2

# We are trying to reach this url via the given HTTP Proxy Server
url="http://www.google.com"

# Timeout time (in seconds)
timeout=1


while read line
    do
    #echo $line

    # HTTP Proxy Server's IP Address (or URL)
    proxy_server=$line

    # We're fetching the return code and assigning it to the $result variable
    #result=`HEAD -d -p http://$proxy_server:$port -t $timeout $url`
    #result=`HEAD -d -p http://$proxy_server -t $timeout $url`
    result=`curl -I -s -x $proxy_server --connect-timeout $timeout $url | head -n 1  | cut -d/ -f1`
    #echo $result

    # If the return code is 200, we've reached to $url successfully
    if [ "$result" = "HTTP" ]; then
        echo "$proxy_server :: OK (proxy works)"

    # Otherwise, we've got a problem (either the HTTP Proxy Server does not work
    # or the request timed out)

    else
        echo "$proxy_server :: ERR (proxy does not work or request timed out)"
    fi

done <$1

一个线程完美运行。但是如何使其成为多线程?我尝试过学期,但是似乎很复杂,而且据我所知。

我希望有人可以帮我

0 个答案:

没有答案