Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the following shell script that tells you good morning, good afternoon, go

ID: 3873678 • Letter: G

Question

Given the following shell script that tells you good morning, good afternoon, good evening, and good night based on the time:

shell script --> hello.sh

current_time=`date|cut -c12-13`

if [ $current_time -ge 06 -a $current_time -lt 12 ]

then

message="Good morning, $USER"

elif [ $current_time -ge 12 -a $current_time -lt 18 ]

then

message="Good afternoon, $USER"

elif [ $current_time -ge 18 -a $current_time -lt 0 ]

then

message="Good evening, $USER"

else

message="Good night, $USER"

fi

echo $message

QUESTION: Expand this program so that it fetches the most current weather reports for KJFK (JFK Airport), KLGA (LaGuardia Airport), and KISP (Long Island McArthur). Also make it print the current temperature, measured in Fahrenheit.

Sample run:

$ ./helloTemp.sh

Good evening, John Doe

The current temperature at KJFK is 55 F

The current temperature at KLGA is 60 F

The current temperature at KISP is 53 F

Hint: use the metar command to obtain a weather report. To convert Celsius to Fahrenheit, use the formula fahrenheit = celsius * 9 / 5 + 32

Explanation / Answer

helloTemp.sh --> script

Script

current_time=`date|cut -c12-13`

if [ $current_time -ge 06 -a $current_time -lt 12 ]

then

message="Good morning, $USER"

elif [ $current_time -ge 12 -a $current_time -lt 18 ]

then

message="Good afternoon, $USER"

elif [ $current_time -ge 18 -a $current_time -lt 0 ]

then

message="Good evening, $USER"

else

message="Good night, $USER"

fi

echo $message

Celsius_Temperature_KJFK='./metar KJFK | cut -f 7 | cut -c1-2'

Fahrenheit_KJFK = 'expr $Celsius_Temperature_KJFK * 9 / 5 + 32'

Celsius_Temperature_KLGA='./metar KLGA | cut -f 7 | cut -c1-2'

Fahrenheit_KLGA = 'expr $Celsius_Temperature_KLGA * 9 / 5 + 32'

Celsius_Temperature_KISP='./metar KISP | cut -f 7 | cut -c1-2'

Fahrenheit_KISP = 'expr $Celsius_Temperature_KISP * 9 / 5 + 32'

echo "The current temperature at KJFK is $Fahrenheit_KJFK F"

echo "The current temperature at KJFK is $Fahrenheit_KLGA F"

echo "The current temperature at KJFK is $Fahrenheit_KISP F"

Explanation

* celsius_Temperature_KJFK stores the value of Temperature in degree centigrade as from "./metar KJFK we get this type of output as "KJFK 161553Z 12007KT 10SM -RA OVC036 07/06 A2965 RMK AO2 SLP046 P0003 T00720061" in which

Location: KJFK
Day of month: 16
Time: 15:53 UTC
Wind: True direction = 120 degrees, Speed: 7 knots
Visibility: 10 Statute Miles
Weather: Light Rain
Clouds: Overcast sky , at 3600 feet above aerodrome level
Temperature: 07 degrees Celsius
Dewpoint: 06 degrees Celsius
QNH: 29.65 inHg

and from which i need 7th field/coloumn that is of type "07/06" in our example case and from that output i need first two characters and finally that value is stored in "celsius_Temperature_KJFK" as 07 in our case.

* Evaluate the fahrenheit convertion based on formula.

metar script --> metar.sh (Reads the weather report based on AIRPORT code)

For this script "KJFK" airport code is default and usage is "metar [airport code]"

Script

if [ -z "$1" ]; then

AIRPORT="KJFK"

elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then

echo "Check the AIRPORT code and enter correctly"

exit 1

else

AIRPORT=$(awk '{print toupper($0)}' <<< $1)

fi

CURLURL="http://weather.noaa.gov/pub/data/observations/metar/stations/"

CURLURL+=$AIRPORT

CURLURL+=".TXT"

curl --silent $CURLURL | grep $AIRPORT

Explanation

It takes AIRPORT code and collects the information from the url.This script might be helpful to you or else you can use your own way to retrive the information from weather report.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote