bash - 使用 WGET 模拟 Web 事件

标签 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 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 结束 if 结构,而不是 done

关于bash - 使用 WGET 模拟 Web 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21042732/

相关文章:

linux - 用于验证 root pw 的 Shell 脚本

linux - 为什么我的 awk 命令多打印一行?

macos - 如何在 Homebrew 软件上安装带有调试支持的 wget?

linux - wget 中的 HTTP 请求占用了大部分时间

linux - 在 bash 中运行时,如何在特定点向脚本发送击键?

bash - 在 Bash 中获取日期(当前时间前一天)

bash - 尝试从单个命令解析多个模式(使用 sed)

linux - 如何使用 unix shell 脚本将多个 csv 文件合并到一个 Excel 工作表中?

bash - 遍历文件并删除某些行

curl - Wget 与 Curl : getting site output with forbidden 403 error