【问题标题】:wget writes post responses to file, and I'm not sure whywget 将帖子回复写入文件,我不知道为什么
【发布时间】:2020-10-17 12:09:11
【问题描述】:

我有一个用于创建 ngrok 隧道的 bash 脚本,然后我使用 dweet.io 发布隧道地址和端口。

如果这对您没有意义,请不要担心,基本上我是在使用 wget --post-data 将字符串发布到地址。

这个 bash 脚本是通过 cron 作业自动启动的。

while true
do
        #Gets the internal IP
        IP="$(hostname -I)"
        #Gets the external IP
        EXTERNALIP="$(curl -s https://canihazip.com/s )"

        echo "Dweeting IP... "

        TUNNEL="$(curl -s http://localhost:4040/api/tunnels)"
        echo "${TUNNEL}" > tunnel_info.json
        #Gets the tunnel's address and port
        TUNNEL_TCP=$(grep -Po 'tcp:\/\/[^"]+' ./tunnel_info.json )

        #Pushes all this information to dweet.io
        wget -q --post-data="tunnel=${TUNNEL_TCP}&internal_ip=${IP}&external_ip=${EXTERNALIP}" http://dweet.io/dweet/for/${dweet_id_tunnel}
        sleep $tunnel_delay
done

这可行,但是,我启动脚本的目录被命名为垃圾邮件的文件

dweet_id_tunnel.1,

dweet_id_tunnel.2,

dweet_id_tunnel.3,

...

这些包含来自 dweet.io 的 wget --post-data 的 HTTP 响应。

由于此脚本会定期运行,因此在文件夹中塞满了数千个此类响应是相当烦人的。我不知道为什么要制作它们,因为我在 wget 中添加了 -q 参数,这应该会抑制响应。

知道我需要更改什么来停止创建这些文件吗?

【问题讨论】:

    标签: bash wget ngrok


    【解决方案1】:

    wget 获取响应并将其保存到文件中;这就是它的作用。如果你不想这样,添加-O /dev/null,或切换到curl,反正你似乎更熟悉,也更通用。

    -q 选项关闭报告, 不下载(即进度消息等,类似于curl -s)。

    【讨论】:

    • 谢谢,我混淆了命令的目的。我用curl 替换了我的wget,现在它的行为完全符合我的要求:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-24
    • 2015-03-27
    • 1970-01-01
    • 2018-05-12
    • 1970-01-01
    • 2019-08-01
    相关资源
    最近更新 更多