#!/bin/sh # Print several web pages, using Unix Netscape and printOpt # Note: this program works well with Netscape 3.* and 4.5(13-Oct-98). # on Netscape 4.0* there is an annoying that Print/Save dialogs # cannot be disabled # $Id: printURL,v 1.3 1999/03/11 17:34:20 ilya Exp $ export NETSCAPE_VERSION NETSCAPE_VERSION=4 #BROWSER_CMD="netscape -noraise -remote " DBG=1 OPT="-gMmta" PRINT_PROGRAM="printOpt $OPT" # any function of a file's content ("sum", "cksum", "wc" etc) SUM_PROGRAM="cksum" case $1 in -X) PRINT_PROGRAM="$2"; OPT="$1 $2"; shift; shift;; -*) PRINT_PROGRAM="printOpt $1"; OPT="$1"; shift;; esac URLS=$* (test -z "$URLS") && echo Enter URLs: && URLS="`cat`" echo "" # note the temporary files should be in a shared directory, not in local /tmp PREFIX=$HOME/tmp-printURL-$$ F1=$PREFIX-one.ps F2=$PREFIX-all.ps FLOG=$PREFIX.log EMPTY=$PREFIX-empty.html echo "Temp files: $PREFIX-{one,all}" (test -r $F2 ) && rm $F2 FetchPage() { test -r $F1 && rm $F1 echo Load $1 ... # netscape -noraise -remote "OpenURL($1)" -remote "SaveAs($F1,PostScript)" || return $? # with older versions one may have to use two separate netscape commands: netscape -noraise -remote "OpenURL($1)" && \ netscape -noraise -remote "SaveAs($F1,PostScript)" || return $? [ "$DBG" ] && echo Loaded. fgrep "interrupted" $F1 && echo "*** page incomplete!? ***"&& return 101 grep -l "^%%Page:" $F1 >/dev/null || return 103 SUM=`$SUM_PROGRAM $F1`; [ "$DBG" ] && echo Checksum: $SUM if [ "$OLDSUM" = "$SUM" ]; then echo "*** page checksum unchanged ***" return 102 else OLDSUM=$SUM fi } echo Sending commands to Netscape... echo>$EMPTY "Please wait..." netscape -noraise -remote "OpenURL(file:$EMPTY)" for x in $URLS; do # echo "printURL $OPT $x" >>$FLOG ERR="" if FetchPage $x; then : else echo "*** error $? *** trying once more..." FetchPage $x || ERR=$? fi head $F1 | egrep '^%%(Pages|Title)' | tee $PREFIX-head egrep "(File not found|ERROR)" $PREFIX-head && ERR=104 if [ "$ERR" ] ; then echo "*** error $ERR, skipping the file ***" else grep -v '^%%EOF' $F1 >>$F2 fi done [ "$DBG" ] && echo $PRINT_PROGRAM $F2 if [ -s $F2 ] then $PRINT_PROGRAM $F2 else echo "*** file $F2 is empty ***" fi