#!/usr/bin/env bash #----------------------------------------------------------------------- # for each run check availability of the input files on FCDFSGI2 and # update the input for making the request # skip files with the save in the name # call: # update_input task_dir [run_number] # # example: # # ~/scripts/update_input /cdf/scratch/cdfopr/cron/stnmaker_express #----------------------------------------------------------------------- . $HOME/.bashrc name=update_input export TASK_DIR=$1 export BOOK_DIR=$TASK_DIR/book export VERBOSE=`cat $TASK_DIR/config/$name | grep VERBOSE | awk '{print $2}'` export EXPR_PROD_HOST=`cat $TASK_DIR/config/$name | grep EXPRESS_PROD_OUTPUT | awk '{print $2}'` export EXPR_PROD_DIR=`cat $TASK_DIR/config/$name | grep EXPRESS_PROD_OUTPUT | awk '{print $3}'` logfile=$TASK_DIR/log/stnmaker_cronjob.log list_of_files=`ls $BOOK_DIR/input/*/* | grep -v save | grep -v done` if [ .$2 != "." ] ; then sbd=`echo $2 | awk '{print substr($1,1,3)}'`; list_of_files=$BOOK_DIR/input/$sbd/$2.aphysr fi list_of_requests=`ls $BOOK_DIR/requests/* | grep -v save` lockfile=$BOOK_DIR/input/update_input.lock #------------------------------------------------------------------------------ # set lock here #------------------------------------------------------------------------------ if [ $VERBOSE -gt 0 ] ; then echo `date` : update_input started, .VERBOSE.=.${VERBOSE}. >> $logfile fi lock_found=`ls $BOOK_DIR/input | grep lock`; while [ ."$lock_found" != "." ] ; do echo `date` : update_input detected lock $lock_found , wait for 30 sec >> $logfile sleep 30 lock_found=`ls $BOOK_DIR/input | grep lock`; done touch $lockfile if [ $VERBOSE -gt 0 ] ; then echo list of files: $list_of_files >> $logfile ; fi fcdfsgi2_list=`rsh -n -X -N $EXPR_PROD_HOST ls $EXPR_PROD_DIR | grep aa | grep phys` rc=$? # echo " rc=$rc, which rsh : " `which rsh` >> $logfile if [ $VERBOSE -gt 0 ] ; then echo fcdfsgi2_list=$fcdfsgi2_list >> $logfile ; fi for file in $list_of_files ; do if [ $VERBOSE -gt 0 ] ; then echo file = $file >> $logfile ; fi list=`cat $file | awk '{ if ($2 == "no") print $1 }'` if [ ."$list" != "." ] ; then #----------------------------------------------------------------------- # input file for this run contains files which are marked as # "not procesed by ExpressProduction" , check if this has been done #----------------------------------------------------------------------- if [ $VERBOSE -gt 0 ] ; then echo list = $list ; fi for f in $list ; do ff=`echo $f | sed 's/ar/aa/'` if [ $VERBOSE -gt 0 ] ; then echo ..$f ... $ff >> $logfile ; fi x=`echo $fcdfsgi2_list | grep $ff` if [ ."$x" != "." ] ; then if [ $VERBOSE -gt 0 ] ; then echo found $x >> $logfile ; fi export EMOE=$f cat $file | awk '{ if (($1 == ENVIRON["EMOE"]) && ($2 == "no")) { $2 = "yes"; printf "%-20s %3s no\n",$1,$2 ; } else { print $0 } }' > ${file}.tmp mv ${file}.tmp $file else if [ $VERBOSE -gt 0 ] ; then echo not found $x " ****************** " >> $logfile fi fi done fi #------------------------------------------------------------------------------ # step 2: # ------- # loop over the list of requests search for already processed files and update # input files correspondingly #------------------------------------------------------------------------------ if [ $VERBOSE -gt 0 ] ; then echo ----- look at the requests >> $logfile ; fi list=`cat $file | awk '{ if (($2 == "yes") && ($3 == "requested")) print $1 }'` if [ $VERBOSE -gt 0 ] ; then echo " ..." list=$list >> $logfile ; fi if [ ."$list" != "." ] ; then #----------------------------------------------------------------------- # for this run there are files which last time had input ready # check if those have been processed #----------------------------------------------------------------------- for f in $list ; do request=`cat $file | grep $f | awk '{print $4}'` if [ $VERBOSE -gt 0 ] ; then echo " " f=$f request=$request >> $logfile ; fi done=`cat $BOOK_DIR/requests/$request | grep $f | awk '{print $3}'` if [ $VERBOSE -gt 0 ] ; then echo done=$done >> $logfile ; fi if [ .$done == ."yes" ] ; then #------------------------------------------------------------------------------ # update input file #------------------------------------------------------------------------------ if [ $VERBOSE -gt 0 ] ; then echo new procesed file: $f >> $logfile ; fi export FN=$f cat $file | awk \ '{ if ($1 == ENVIRON["FN"]) { printf "%-20s yes yes \n",$1 } else { printf "%s\n" ,$0 } }' > $file.tmp if [ $VERBOSE -gt 0 ] ; then echo -------------- $file.tmp >> $logfile ; fi if [ $VERBOSE -gt 0 ] ; then cat $file.tmp >> $logfile ; fi if [ $? == 0 ] ; then mv $file.tmp $file ; fi fi done fi done #------------------------------------------------------------------------------ # finally release lock # rm $lockfile if [ $VERBOSE -gt 0 ] ; then echo `date` : update_input finished >> $logfile fi #------------------------------------------------------------------------------