Bash,循环意外停止

时间:2018-03-28 19:50:17

标签: bash loops curl scripting

我的bash脚本的最后一部分出了问题。它接收来自500个Web地址的输入,并且应该从每个地址获取服务器信息。它有点工作,但就像45元素一样停止。我的循环最后有什么想法吗?

#initializing variables 
timeout=5
headerFile="lab06.output"
dataFile="fortune500.tsv"
dataURL="http://www.tech.mtu.edu/~toarney/sat3310/lab09/"
dataPath="/home/pjvaglic/Documents/labs/lab06/data/"
curlOptions="--fail --connect-timeout $timeout"

#creating the array
declare -a myWebsitearray

#obtaining the data file
wget $dataURL$dataFile -O $dataPath$dataFile

#getting rid of the crap from dos
sed -n "s/^m//" $dataPath$dataFile

readarray -t myWebsitesarray < <(cut -f3 -d$'\t' $dataPath$dataFile)

myWebsitesarray=("${myWebsitesarray[@]:1}")

websitesCount=${#myWebsitesarray[*]}

echo "There are $websitesCount websites in $dataPath$dataFile"

#echo -e ${myWebsitesarray[200]}

#printing each line in the array
for line in ${myWebsitesarray[*]}
do
echo "$line"
done

#run each website URL and gather header information
for line in "${myWebsitearray[@]}"
    do
        ((count++))
        echo -e "\\rPlease wait... $count of $websitesCount"
        curl --head "$curlOptions" "$line" | awk '/Server: / {print $2 }' >> $dataPath$headerFile       
    done

#display results
echo "Results: "
sort $dataPath$headerFile | uniq -c | sort -n

1 个答案:

答案 0 :(得分:0)

如果您实际上通过了--connect-timeout选项以进行卷曲,那肯定会有所帮助。如所写,您当前正在传递单个参数--fail --connect-timeout $timeout,而不是3个不同的参数--fail--connect-timeout$timeout。这是一个不应引用该变量的实例。 IOW,使用:

curl --head $curlOptions "$line"