LDP/LDP/guide/docbook/abs-guide/quote-fetch.sh

33 lines
833 B
Bash

#!/bin/bash
# quote-fetch.sh: Download a stock quote.
E_NOPARAMS=66
if [ -z "$1" ] # Must specify a stock (symbol) to fetch.
then echo "Usage: `basename $0` stock-symbol"
exit $E_NOPARAMS
fi
stock_symbol=$1
file_suffix=.html
# Fetches an HTML file, so name it appropriately.
URL='http://finance.yahoo.com/q?s='
# Yahoo finance board, with stock query suffix.
# -----------------------------------------------------------
wget -O ${stock_symbol}${file_suffix} "${URL}${stock_symbol}"
# -----------------------------------------------------------
exit $?
# Exercises:
# ---------
#
# 1) Add a test to ensure the user running the script is on-line.
# (Hint: parse the output of 'ps -ax' for "ppp" or "connect."
#
# 2) Modify this script to fetch the local weather report,
#+ taking the user's zip code as an argument.