2014-01-10 57 views
2

我目前正在編寫一個Bash腳本來模擬網絡活動。這個想法是腳本運行了大約三個小時,然後終止。使用WGET模擬網絡活動

我已經沒有問題了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

回答

4

你最終的if構建與fi,不done

1

最終腳本爲未來的Google ...我罐頭在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 
+0

你可以用空格定義IN,然後直接使用'for x in $ IN;像[我的版本](https://gist.github.com/rubo77/6f3abb42685237dfca16)和「few.vu.nl/~kgr700/ ..」一樣是空的 – rubo77