#!/bin/sh # # Sample URI-fetching routine that uses lynx. In order for this # to work, you must, obviously, have lynx installed. # # Syntax is as follows: # # get_uri # # Exit codes: # # 1: remote HTTP daemon returned a non-200 code or mktemp failed # 2: temp file couldn't be renamed # 3: incorrect number of arguments # # Output: # # After storing URL (arg 1) in tmpfile (arg 2), url_get prints to # stdout the actual URL that was fetched (redirects may make it # so that the URL given as arg 1 isn't the one actually placed in # tmpfile). prefix=@prefix@ PATH=@exec_prefix@/bin:$PATH LYNX="@LYNX@ -restrictions=all" MKTEMP=@MKTEMP@ if test .$# != .2; then exit 3; fi progname=`basename $0` tmpfile=`${MKTEMP} "/tmp/${progname:-get_uri}.XXXXXXX" 2> /dev/null` || exit 1 errfile=`${MKTEMP} "/tmp/${progname:-get_uri}.XXXXXXX" 2> /dev/null` || exit 1 ${LYNX} -source -dump -telnet \ -restrictions=all \ -hiddenlinks=ignore \ -error_file=${errfile} \ "${1}" 1> ${tmpfile} 2> /dev/null if test ${?} = 0 && \ (test ! -s ${errfile} || \ egrep 'STATUS=HTTP.* 200 ' ${errfile} 1> /dev/null 2>&1) then mv ${tmpfile} "${2}" 2> /dev/null || exit 2 sed -n 's/^ *UR[IL]=\([^ ][^ ]*\) .*$/\1/p' < ${errfile} 2> /dev/null test -f ${errfile} && rm -f ${errfile} 2> /dev/null exit 0 else test -f ${errfile} && rm -f ${errfile} 2> /dev/null test -f ${tmpfile} && rm -f ${tmpfile} 2> /dev/null exit 1 fi