Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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
Bash 使用WGET模拟web活动_Bash_Shell_Wget - Fatal编程技术网

Bash 使用WGET模拟web活动

Bash 使用WGET模拟web活动,bash,shell,wget,Bash,Shell,Wget,我目前正在编写一个Bash脚本来模拟web活动。这个想法是脚本运行大约三个小时,然后终止 我对wget没有问题,oneliner在cmd行上工作得非常好 代码如下: #!/bin/bash a=$(date +%s) echo current time is $a b=$(($a + 10800)) # finish time is start time plus 10800 number of seco\ # nds in three hours echo

我目前正在编写一个Bash脚本来模拟web活动。这个想法是脚本运行大约三个小时,然后终止

我对wget没有问题,oneliner在cmd行上工作得非常好 代码如下:

#!/bin/bash

a=$(date +%s)
echo current time is $a
b=$(($a + 10800))   # finish time is start time plus 10800 number of seco\
                # nds in three hours
echo finish time is $b
for line in "url_list.txt"; do
     echo current url is $line
     date=$(date +%s)
     echo current time is $c
     wget -e \
       -r -p -l 1 -T 60 \
       --random-wait --user-agent="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092416 Firefox/3.0.3" \
       --convert-links\
     echo "downloading..." 
     echo "Calculating if three hours has passed..."
     if (("$date" > "$b"))
     then
         echo "3 hours has passed£
         break
     else
         echo sleep for 5 seconds
         sleep 5;
     done;
我得到了一个错误:

url_request.sh: line 26: syntax error near unexpected token `done'
url_request.sh: line 26: `      done'

发生了什么事,我看不见?

在bash中,如果用
fi
构造
,而不是
完成
为未来的谷歌人编写的最终脚本,你将结束
。。。我屏蔽了for循环,因为我将使用Cron作业

#!/usr/bin/env bash

IN="http://download.thinkbroadband.com/50MB.zip;http://www.bbc.co.uk;http://www.few.vu.nl/~kgr700/cloud%20computing%20and%20emerging%20it%20platforms.pdf;http://www.theregister.co.uk;http://en.wikipedia.org/wiki/cloud_computing"

arr=$(echo $IN | tr ";" "\n")

while true; do
    for x in $arr
    do
    echo downloading $x
    wget -r -p -l 2 -T 60 $x --random-wait --user-agent="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092416 Firefox/3.0.3" --convert-links -a logfile.txt
    done
done

您可以使用空格来定义IN,然后直接在$IN中为x使用
;执行
like in,并且“now.vu.nl/~kgr700/”为空