Send As SMS

Saturday, October 28, 2006

Using wget in scripts

Wget, or at least the version of it in Debian Sarge, does not adhere to the usual UNIX norms (if all goes well then generate no error messages and exit zero, if there's a problem then generate error message(s) and exit non-zero). Here is how to use it to emulate this behaviour:
wget URL &>log || ( cat log >&2 ; rm -f log ; false )
The problem is that wget is built to be chatty and, although it does exit non-zero on error, it does not appear to be possible to reliably configure it to emit an error message in this case but emit nothing in the non-error cases:
  • -q silences all messages
  • -nv, which is supposed to silence the chatter also appears to silence error messages. I'd say that this is a bug, however the GNU folks appear to lack a current maintainer for wget.
UPDATE 2006-10-28: Close, but no cigar.
wget URL &>log && rm -f log || ( cat log >&2 ; rm -f log ; false )
Now the log file now disappears on success, as well as on failure.