You can either check (with test -s
) that the file has contents, or simply use the return value of wget
. Download to a temporary file, and only if the test passes, then copy to the real output:
$ wget -q -O /tmp/a http://localhost/nonexistent && mv -v /tmp/a /tmp/b $ wget -q -O /tmp/a http://localhost && mv -v /tmp/a /tmp/b ‘/tmp/a’ -> ‘/tmp/b’ $