#!/bin/bash
PATH=/bin:/usr/bin:/usr/ucb:/usr/local/contrib/bin:/usr/local/bin
REFRESH="`TZ=EST5EDT date +'%c %z' -d '+300 seconds'`"
TITLE="Real-Time Stock Quote - `TZ=EST5EDT date`"
if [ "$REQUEST_URI" != "" ] ; then
	echo 'Content-Type: text/html'
	echo
	echo '<HTML> <BODY BGCOLOR="#FFFFFF">'
	echo '<META HTTP-EQUIV="Expires" CONTENT="'$REFRESH'">'
	echo '<META HTTP-EQUIV="Refresh" CONTENT="303">'
	echo '<TITLE>'$TITLE'</TITLE>'
	# include standard header
	# cat /htdocs/include/includes/standard.shtml
	echo '<FORM METHOD="GET" ACTION="/cgi-bin/getquotes">'
	echo '<FONT COLOR="#0000AA"><B>'$TITLE'</B></FONT>'
	echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Quotes'
	echo '<INPUT TYPE="TEXT" SIZE="12" NAME="s"></FORM>'
	echo '<HR><SMALL><PRE>'
else
	QUERY_STRING='s='$1
	if [ "$QUERY_STRING" = "s=" ] ; then
		QUERY_STRING=""
	fi
	echo $TITLE
fi

STOCK_QUERY='s=^DJI+^IXIC+^N225+^SPC+AMD+GOOG+HPQ+IBM+INTC+LNUX+MSFT+ORCL+RHAT+SUNW+TMTA+TWX+YHOO'

if [ "$QUERY_STRING" != "" ] ; then
	STOCK_QUERY=$QUERY_STRING
fi

wget -q -O - 'http://finance.yahoo.com/d/q?'${STOCK_QUERY}'&f=st5nl9c6ghv' | sed s/\"//g | awk -F, '
{
	if (int($8) < 1) {
	    if ($4 > 0) {
		printf("%8s %-16s (%-5s) %9.3f %+8.3f %11.3f   -%11.3f\n",
			$2, $3, $1, $4, $5, $6, $7);
	    }
	} else {
		printf("%8s %-16s (%-5s) %9.3f %+8.3f (%7.3f-%7.3f)%9d\n",
			$2, $3, $1, $4, $5, $6, $7, $8);
	}
}'
if [ "$REQUEST_URI" != "" ] ; then
	echo '</PRE></SMALL><HR>'
	echo 'Stocks may be innaccurately quoted.&nbsp;&nbsp;<A'
	echo 'HREF="http://finance.yahoo.com/q?'${STOCK_QUERY}'">'
	echo 'Yahoo!<FONT SIZE="-4">&reg;</FONT> Finance</A>'
	echo 'contains the full information quoted.<P>'
	echo '<A HREF="http://biz.yahoo.com/t/t/tmta.html">Insider Trades</A><P>'
	echo '<FONT SIZE="-4"><FONT COLOR="#FF0000">'
	echo 'WARNING: This page will refresh every five minutes.</FONT>'
	echo '&nbsp;&nbsp;Next refresh '$REFRESH'</FONT>'
	# include standard footer
	# cat /htdocs/include/includes/footer.shtml
	echo '</BODY> </HTML>'
fi
