#!/bin/sh # Format of Moongiant.com query # http://www.moongiant.com/phase/MM/DD/YYYY # if no date specified, just use "today": if test $Argc -eq 0 { setglobal thedate = '"today'" } else { # date specified. Let's check to see if it's in the right format setglobal mon = $[echo $1 | cut -d/ -f1] setglobal day = $[echo $1 | cut -d/ -f2] setglobal year = $[echo $1 | cut -d/ -f3] if test -z $year -o -z $day { # zero length? echo "Error: only valid date format is MM/DD/YYYY" exit 1 } # You could add additional date checking code here, or invoke # the earlier script checkdate setglobal thedate = $1 # no error checking = dangerous } echo checking moon phase for day = $thedate setglobal url = ""http://www.moongiant.com/phase/$thedate"" setglobal pattern = '"Illumination:'" setglobal phase = $[ curl -s $url | grep $pattern | tr ',' '\ ' | grep $pattern | sed 's/[^0-9]//g] # format from this is "Illumination: 74%\n<\/span>" if test $thedate = "today" { echo "Today the moon is $(phase)% illuminated." } else { echo "On $thedate the moon = $(phase)% illuminated." } exit 0