#!/usr/bin/ksh # # wget_usgs_gmag.ksh # # Author: Lydia Philpott (lphilpott@igpp.ucla.edu) # # Based heavily on wget_intermagnet_gmag.ksh # # This script uses wget to download data from USGS magnetometer sites # # This script is initially being set up to download data from BRW (Barrow). With the intention # that it be extendable to other sites in the future. # # $1 = site # $2 = year # $3 = month # ## Set environment variables # if [[ -z $THMSOC ]] then THMSOC=/disks/socware/thmsoc_dp_current #THMSOC=/home/thmsoc/lphilpotts_stuff export THMSOC fi . $THMSOC/src/config/soc_it_to_me.config . $THMSOC/src/config/wget_usgs_gmag.config #. $THMSOC/soc_it_to_me.config #. $THMSOC/wget_usgs_gmag.config # ## Handle input arguments # site=${1} year=${2} month=${3} # ## Set logfiles # processdate=$(date '+%y%m%d') LOGFILE=${LOGDIR}/webdownloads/usgs_gmag_log_${processdate} WGETLOG=${LOGDIR}/webdownloads/wget_output_usgs_gmag_${processdate}_${site}_$$ echo ":$$:usgs_gmag_log:" >> $LOGFILE echo ":$$:usgs_gmag_log:Starting script wget_usgs_gmag at $(date)" >> $LOGFILE # ## Run wget to download data from usgs for given site # if [[ $os = "SunOS" ]] then siteupper=$(echo $site | nawk '{print toupper($1)}') else siteupper=$(echo $site | awk '{print toupper($1)}') fi wgetTime=$(date '+%Y-%m-%d %T') url=${WEBSITE}/$siteupper/OneSecond/ sitequery="$site$year$month*" /usr/bin/wget -r -nH --cut-dirs=5 -N -o $WGETLOG -P $LOCALWEBMIRROR/${site}/${year}/${month} -A $sitequery -np $url echo ":$$:usgs_gmag_log: Download Complete: $site" >> $LOGFILE # ## Parse through wget output to see what was downloaded # grep saved $WGETLOG | grep -v 'index\|robot' | awk '{print $6 " " $8}' > /tmp/wget_usgs_gmag$$ while read line do echo "line: $line" path=$(echo $line |awk '{print $1}') size=$(echo $line |awk '{print $2}') fileName=$(basename $path) fileName=${fileName%*\'} # Parse date information from filename year=$(echo $fileName |awk -F_ '{print substr($1,4,4)}') mon=$(echo $fileName |awk -F_ '{print substr($1,8,2)}') day=$(echo $fileName |awk -F_ '{print substr($1,10,2)}') fileTime="${year}-${mon}-${day} 00:00:00" # Verify file exists if [[ ! -a ${LOCALWEBMIRROR}/${site}/${year}/${month}/${fileName} ]] then echo "$$:usgs_gmag_log:" >> $LOGFILE echo "$$:intermagnet_gmag_log: ${LOCALWEBMIRROR}/${site}/${year}/${month}/${fileName} not found. " >> $LOGFILE echo "$$:intermagnet_gmag_log: continuing..................." >> $LOGFILE fi fileSize=${size%\]} fileSize=${fileSize#\[} # Update database with stats ${PHP_SCRIPTS}/wget_usgs_gmag.php $fileName $wgetTime $fileTime $fileSize # Create a file used for CDF processing cp ${LOCALWEBMIRROR}/${site}/${year}/${month}/${fileName} ${GMAGWORKDIR}/$fileName done < /tmp/wget_usgs_gmag$$ # ## Cleanup # rm -f /tmp/wget_usgs_gmag$$ exit 0