#!/bin/sh -u # This CGI script displays the temperature for a given city code # ------------------------------------------------------------------ # Syntax: $0 [city_code] # ------------------------------------------------------------------ # Purpose: Fetch the weather in a CGI script. # Optional argument is the Environment Canada city code. # A missing argument means we use code on-118 (Ottawa). # If we can't find any weather for that code, we issue a message. # Since this is a CGI script, I assume only one argument and I # don't set any particular exit code. (Should fix that.) # ------------------------------------------------------------------ # # Comment: the required comments are missing from this sample solution # ------------------------------------------------------------------ exec 2>&1 PATH=/bin:/usr/bin ; export PATH umask 022 LC_COLLATE=C ; export LC_COLLATE # BONUS part - uncomment the two IF statement lines (and fix indentation): # # if ! tty -s ; then echo "Content-Type: text/plain" echo "" # fi if [ $# -eq 0 ] ; then city=on-118 # echo "DEBUG: Using default city code $city" else city="$1" # echo "DEBUG: Using argument city code $city" fi URL="http://text.weatheroffice.ec.gc.ca/forecast/city_e.html?$city" output=$( lynx -dump "$URL" | grep -A 1 Temperature: | tr ' \n' ' ' ) if [ "$output" = "" ] ; then echo "$0: Could not find temperature for city code '$city'" else echo "$0: The current temperature in $city is:" echo "$output" fi