#!/usr/bin/ksh # # wget_green_gmag.ksh # # Author: Patrick Cruce(pcruce@igpp.ucla.edu) # # Based heavily on wget_nrsq_gmag.ksh and wget_maccs_gmag.ksh by Tim Quinn(teq@ssl.berkeley.edu) # # Modified oct-27-2011 (lphilpott): # Download is changing from manual to auto thus some changes to script so that files that already exist # are not overwritten or sent for processing to cdf. # Also changed the logging so that there is only one logfile per download date (per site). # # $1 = site # $2 = year # $3 = month # $4 = day # ## Set environment variables # if [[ -z $THMSOC ]] then THMSOC=/disks/socware/thmsoc_dp_current export THMSOC fi . $THMSOC/src/config/soc_it_to_me.config #. $THMSOC/src/config/wget_green_gmag.config . /home/thmsoc/lphilpotts_stuff/greenland_test/wget_green_gmag_backfiles.config # ## Handle input arguments # site=${1} year=${2} month=${3} day=${4} # ## Set logfiles # processdate=$(date '+%y%m%d') #changing to one log file per process date LOGFILE=${LOGDIR}/webdownloads/green_gmag_log_${processdate} #LOGFILE=${LOGDIR}/webdownloads/green_gmag_log_${processdate}_$$ #changing to one log file per process date per site WGETLOG=${LOGDIR}/webdownloads/wget_output_green_gmag_${processdate}_${site} #WGETLOG=${LOGDIR}/webdownloads/wget_output_green_gmag_${processdate}_$$ echo ":$$:green_gmag_log:" >> $LOGFILE echo ":$$:green_gmag_log:Starting script wget_green_gmag at $(date)" >> $LOGFILE # ## Run wget to download data from Greenland GMAG Network # filename=green_${site}_${year}${month}${day}_min.min wgetTime=$(date '+%Y-%m-%d %T') url=${WEBSITE}\?site=${1}\&year=${2}\&month=${3}\&day=${4}\&${WEBOPTS} downloadfile=$(echo ${url} |awk -F\/ '{print $5}') downloadfilename=${LOCALWEBMIRROR}/${site}/${year}/${month}/${downloadfile} outfile=${LOCALWEBMIRROR}/${site}/${year}/${month}/${filename} # -r: recursive, -l 1: 1 level - prob unnec, -nd: don't create directories # -N checks time stamping, but this doesn't work with -O (write output to the one file listed) # there is no time stamping on the files anyway! #/usr/bin/wget -r -l 1 -nd -o $WGETLOG -O $outfile $url # leaving -N so that on the off chance some file with the long url name exists the new file won't get downloaded as .1 /usr/bin/wget -nd -N -a $WGETLOG -P $LOCALWEBMIRROR/${site}/${year}/${month} $url # -e test is the same as -a (deprecated) echo ":$$:green_gmag_log: Download Complete: $site" >> $LOGFILE if [[ -e $downloadfilename ]] then #echo "File downloaded" #if file already exists check to see if new file is different if [[ -e $outfile ]] then cmp -s $downloadfilename $outfile filediff=$? #echo "File diff: $filediff" if [[ $filediff -ne 0 ]] then # check for errors in the download that may slip through even though file is downloaded echo "$$:green_gmag_log:" >> $LOGFILE echo "$$:green_gmag_log: Downloaded file different to existing file." >> $LOGFILE grep -i "error" ${WGETLOG} >> /dev/null if [[ $? -eq 0 ]] then echo "$$:green_gmag_log:" >> $LOGFILE echo "$$:green_gmag_log: ${downloadfilename} download error" >> $LOGFILE rm -f ${downloadfilename} exit 1 fi mv $downloadfilename $outfile cp $outfile ${GMAGWORKDIR}/${filename} else echo "$$:green_gmag_log:" >> $LOGFILE echo "$$:green_gmag_log: Downloaded file same as existing file." >> $LOGFILE rm -f $downloadfilename fi # if file doesn't already exist just check for errors and rename else grep -i "error" ${WGETLOG} >> /dev/null if [[ $? -eq 0 ]] then echo "$$:green_gmag_log:" >> $LOGFILE echo "$$:green_gmag_log: ${downloadfilename} download error" >> $LOGFILE rm -f ${downloadfilename} exit 1 fi mv $downloadfilename $outfile cp $outfile ${GMAGWORKDIR}/${filename} fi else echo "$$:green_gmag_log:" >> $LOGFILE echo "$$:green_gmag_log: ${downloadfilename} not found. " >> $LOGFILE echo "$$:green_gmag_log: No file downloaded?" >> $LOGFILE exit 1 fi # ## Parse through wget output to see what was downloaded # # Verify file exists #if [[ ! -a ${outfile} ]] #then # echo "$$:green_gmag_log:" >> $LOGFILE # echo "$$:green_gmag_log: ${outfile} not found. " >> $LOGFILE # exit 1 #fi #grep -i "error" ${WGETLOG} >> /dev/null #if [[ $? -eq 0 ]] #then # echo "$$:green_gmag_log:" >> $LOGFILE # echo "$$:green_gmag_log: ${outfile} download error" >> $LOGFILE # rm -f ${outfile} # exit 1 #fi #copy file into temporary location so it will be queued for downstream processing #cp $outfile ${GMAGWORKDIR}/${filename} # fileSize=$(echo $size |awk -F/ '{print $2}') # fileSize=${fileSize%*\]} # Update database with stats # ${PHP_SCRIPTS}/wget_nrsq_gmag.php $fileName $wgetTime $fileTime $fileSize # Create a file used for CDF processing # touch ${GMAGMIRROR}/$fileName exit 0