Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 为什么我在文件中读取的nohup bash脚本总是在文件结束之前停止输出6k左右的计数?_Linux_Bash_Centos7_Nohup - Fatal编程技术网

Linux 为什么我在文件中读取的nohup bash脚本总是在文件结束之前停止输出6k左右的计数?

Linux 为什么我在文件中读取的nohup bash脚本总是在文件结束之前停止输出6k左右的计数?,linux,bash,centos7,nohup,Linux,Bash,Centos7,Nohup,我使用nohup运行bash脚本来读取文件的每一行(并提取我需要的信息)。我在多个不同行大小的文件上使用过它,大多数在50k到100k之间。但无论我的文件有多少行,nohup总是在最后一行之前6k左右停止输出信息 我的脚本名为:fetchStuff.sh #!/bin/bash urlFile=$1 myHost='http://example.com' useragent='me' count=0 total_lines=$(wc -l < $urlFile) while read

我使用nohup运行bash脚本来读取文件的每一行(并提取我需要的信息)。我在多个不同行大小的文件上使用过它,大多数在50k到100k之间。但无论我的文件有多少行,nohup总是在最后一行之前6k左右停止输出信息

我的脚本名为:fetchStuff.sh

#!/bin/bash

urlFile=$1
myHost='http://example.com'
useragent='me'
count=0
total_lines=$(wc -l < $urlFile)

while read url; do
    if [[ "$url" == *html ]]; then continue; fi

    reqURL=${myHost}${url}
    stuffInfo=$(curl -s -XGET -A "$useragent" "$reqURL" | jq -r '.stuff')
    [ "$stuffInfo" != "null" ] && echo ${stuffInfo/unwanted_garbage/} >> newversion-${urlFile}
    ((count++))
    if [ $(( $count%20 )) -eq 0 ]
    then
        sleep 1
    fi
    if [ $(( $count%100 )) -eq 0 ]; then echo "$urlFile read ${count} of $total_lines"; fi
done < $urlFile

我不明白为什么它总是在文件结束前6k左右停止。(我设置了睡眠计时器,以避免在大量请求的情况下淹没api)。

循环跳过以
html
结尾的行,它们不计入
$count
。所以我敢打赌,在
file1.txt
中有6317行以
html
结尾,在
file2.txt
中有5376行,依此类推

如果希望
$count
包含它们,请将
((count++)
放在检查后缀的
If
语句之前

while read url; do
    ((count++))
    if [[ "$url" == *html ]]; then continue; fi

    reqURL=${myHost}${url}
    stuffInfo=$(curl -s -XGET -A "$useragent" "$reqURL" | jq -r '.stuff')
    [ "$stuffInfo" != "null" ] && echo ${stuffInfo/unwanted_garbage/} >> newversion-${urlFile}
    if [ $(( $count%20 )) -eq 0 ]
    then
        sleep 1
    fi
    if [ $(( $count%100 )) -eq 0 ]; then echo "$urlFile read ${count} of $total_lines"; fi
done < $urlFile
您可以使用

grep -v 'html$' "$urlFile" | while read url; do
    ...
done

我想。我只是在发帖几分钟后想到了跳行!就像他们说的“橡皮鸭”。
total_lines=$(grep -c -v 'html$' "$urlFile")
grep -v 'html$' "$urlFile" | while read url; do
    ...
done