#!/bin/sh prog=${0##*/} usage() { cat <&2 fi } OPTS=$(getopt -l quiet,help,spider -o "qhO:" -n $prog -- "$@") || usage "1" >&2 quiet= eval set -- "$OPTS" while true; do opt="$1" case "$opt" in -h|--help) usage 0 ;; -q|--quiet) quiet=1 ;; --spider) exit ${SPIDER_STATUS:-0} ;; -O) shift outfile="$1" ;; --) shift break ;; *) usage "1" >&2 ;; esac shift done for url; do case "$url" in *fail*) msg "bad address"; exit 1;; *404*) msg "wget: server returned error: HTTP/1.1 404 Not Found"; exit 1;; esac done : ${outfile:=index.html} case "$outfile" in -) msg "writing to stdout" echo "$WGETCONTENT" ;; *) msg "saving to '$outfile'" echo "$WGETCONTENT" > "$outfile" ;; esac