#!/bin/sh -u # Fetch the current temperature for a given airport city code # -------------- # Syntax: $0 airport_code # -------------- # Purpose: # Given an Environment Canada 3-letter city code argument, fetch the # weather page for that city, extract and display the temperature. # Bonus: Extract the city name too. # -------------- #Student Name: Ben Dover #Algonquin EMail Address: abcd0001 #Student Number: 074-210-779 #Course Number: DAT2330 #Lab Section Number: 014 #Professor Name: Ian Allen #Assignment Name/Number/Date: Exercise #3 due March 9, 2004 #Comment: number two of two files for this exercise # Set a standard search PATH and friendly umask # PATH=/bin:/usr/bin ; export PATH umask 022 # Fetch the weather using the Environment Canada URL. # Use a unique tmp file name in /tmp to hold the fetched weather page. # (Note the need to quote the URL because of the shell metacharacter.) # tmpfile=/tmp/weather$USER.$$ lynx -dump "http://weatheroffice.ec.gc.ca/forecast/city_e.html?$1" >"$tmpfile" # Scan the tmp file to extract the temperature and (BONUS) the city name. # Remove the tmp file when done. # Display the output. # temp=$( grep 'Temp.:' "$tmpfile" | awk '{print $2}' ) city=$( grep ': Issued' "$tmpfile" | cut -d ':' -f 1 ) rm "$tmpfile" echo "The temperature in $1 ($city) is $temp right now." # The script exits with the exit code of the last command executed.