#!/usr/bin/ksh set -vx # JCET mod # Note to users: This script is intended to aid you with retrieving USNO # EOP data from our primary server, or, if our primary server is unavailable # for a defined amount of time, our back-up server in Flagstaff, Arizona. # The script will check the primary site for 30 minutes for new data. If, # after that amount of time, the file time stamp has not changed, the script # will begin to check the secondary site as well. If there is an update, # the script will quietly terminate. # The script can be set to check the status of files some time later during # the day to see if the files you wish to retrieve have been updated. typeset RC=0 typeset COUNT=1 typeset idone=0 # Define wget path WGETPATH=/usr/bin/ # Define file variables that exist locally # This can be called whatever you wish MYFINALSDAILY=finals2000A.daily.local # Define file variables you wish to download. # The names should correspond to how they are named on the server. FINALSDAILY=finals2000A.daily # Open and timestamp a log exec >> ${ARCHIVE}getusnolog-$(date +%Y-%m-%d) 2>&1 # Get current date in MMMDYYYY format today=$(date +%m/%d/%Y) echo $today # Get user's locale 12-hour clock time hour=$(date +%r) # E-mail declarations # Declare your e-mail address here if you wish to be notified by e-mail # when new data is available. # Declare variables for primary and secondary ftp sites maia=primary toshi=secondary # Compare file time stamps of local file and the one downloaded from the server. function check_timestamp { file1time=$(stat -c %Y $MYFINALSDAILY) file2time=$(stat -c %Y $FINALSDAILY) #(( diff = $file1time - $file2time )) (( diff = $file2time - $file1time )) #if (( "$diff" < 0 )) ; then if (( "$diff" > 43200 )) ; then # if local file is older than server file... # server file has been updated # if frc=0, it means that the server file is new frc=0 else frc=1 fi return $frc } # Check primary ftp site for 30 minutes while [[ $COUNT -le 360 && $idone -ne 1 ]]; do ### maia.usno.navy.mil newer=$(${WGETPATH}wget -N --tries=5 --timeout=180 ftp://maia.usno.navy.mil/ser7/${FINALSDAILY} 2>&1) echo $newer check_timestamp if [ $frc -eq 0 ] ; then # if primary site has been updated within the 30 minute time frame # it is OK to exit idone=1 if ((`echo $newer | grep -c "Remote file is newer"` > 0 )) ; then datamsg="On $today, at $(date +%r), new data was retrieved from $maia site." echo $datamsg | mailx -s "USNO EOP DATA UPDATE" $emaillist mv $FINALSDAILY $MYFINALSDAILY # JCET mod fi fi let COUNT=COUNT+1 # sleep 5 seconds between each download attempt sleep 5 done # Now begin to check both maia and toshi for a minimum of two and a half hours # Also e-mail user if there has been an update to the file # Reset the counter. let COUNT=0 while [[ $idone -eq 0 && $COUNT -le 900 ]]; do ### maia.usno.navy.mil newer=$(${WGETPATH}wget -N --tries=5 --timeout=180 ftp://maia.usno.navy.mil/ser7/${FINALSDAILY} 2>&1) echo $newer check_timestamp if [ $frc -eq 0 ] ; then idone=1 if ((`echo $newer | grep -c "Remote file is newer"` > 0 )) ; then # E-mail user that new data was retrieved datamsg="On $today, at $(date +%r), new data was retrieved from $maia site." echo $datamsg | mailx -s "USNO EOP DATA UPDATE" $emaillist mv $FINALSDAILY $MYFINALSDAILY # JCET mod fi fi ### toshi.nofs.navy.mil newer=$(${WGETPATH}wget -N --tries=5 --timeout=180 ftp://toshi.nofs.navy.mil/ser7/${FINALSDAILY} 2>&1) check_timestamp echo $newer if [ $frc -eq 0 ] ; then idone=1 if ((`echo $newer | grep -c "Remote file is newer"` > 0 )) ; then # E-mail user that new data was retrieved datamsg="On $today, at $(date +%r), new data was retrieved from $toshi site." echo $datamsg | mailx -s "USNO EOP DATA UPDATE" $emaillist mv $FINALSDAILY $MYFINALSDAILY # JCET mod fi fi let COUNT=COUNT+1 if [ $COUNT -gt 900 ] ; then datamsg="On $today, there were no additional updates to the files on neither the $maia site nor $toshi site." echo $datamsg | mailx -s "No USNO EOP data update" $emaillist fi # sleep 10 seconds between each download attempt sleep 10 done echo "Finished"