如何获取wget仅在完整的情况下保存文件 [英] How to get wget only save file if its complete

查看:50
本文介绍了如何获取wget仅在完整的情况下保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用wget这样下载文件

I downloading files using wget like this

wget http://www.example.com/mysql.zip -O mysql.zip

然后我要处理该文件.

但是有时如果URL或某处有错误,则损坏的文件 mysql.zip

But sometimes if there is error in url or somewhere then corrupted file mysql.zip

放置在此处,并且我的脚本未下载文件,因为该文件已经存在并且脚本失败.

is placed in there and my script don't download the file as its already there and script fails.

如果仅在文件下载完成后才放置 mysql.zip ,有什么办法.

Is there any way if mysql.zip is only placed if file download is complete.

有两种情况可能会发生

  1. 网址不存在
  2. 用户手动取消下载

在上述两种情况下,我都不希望文件存在

IN both above cases i don't want the file to be there

推荐答案

这个bash脚本怎么样:

What about this bash script:

#!/bin/bash
if wget http://www.example.com/mysql.zip -O mysql.zip
then
    # Do something with file
else
    rm mysql.zip
fi

这篇关于如何获取wget仅在完整的情况下保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆