uportal_merge_daily_logs.sh

(nl85@orpheus7)/users/nl85> cat uportal_merge_daily_logs.sh
#!/bin/ksh
#
##-------------------------------------------------------------------
# 
# Script: uportal_merge_daily_logs.sh
# 
#               combine all files in yesterdays log dir
#               in prep for awstats run for uportal.cornell.edu
#             
# Description: 
#               combine all files in yesterdays log dir
#               as a sorted Apache log file based on the date being in 
#               key 4th dictionary sort 
#             
# Date: 2010-Jan
#  
# 
##-------------------------------------------------------------------

RETCODE=0
RETCODE_MSG=""

FILE_NAME=merged_sorted_file.log

YESTERDAY=`TZ=EST+24 date +%Y%m%d`

#echo $YESTERDAY
#echo FILE_NAME=$FILE_NAME

yesterdayYYYY=$(echo $YESTERDAY|cut -c1-4) 
yesterdayMM=$(echo $YESTERDAY|cut -c5-6)
yesterdayDD=$(echo $YESTERDAY|cut -c7-8) 

# echo "yesterdayYYYY/MM/DD =$yesterdayYYYY/$yesterdayMM/$yesterdayDD"
# ls /global/tc/log/tcweb-managed-apache-logs/uportal_access_log/$yesterdayYYYY/$yesterdayMM/$yesterdayDD

YESTERDAYS_LOG_DIR=/global/tc/log/tcweb-managed-apache-logs/uportal_access_log/$yesterdayYYYY/$yesterdayMM/$yesterdayDD

#-----------------------------------
# check to besure directory is there 
#-----------------------------------
if [[ ! -d $YESTERDAYS_LOG_DIR ]]
then 
  RETCODE=1
  RETCODE_MSG="$YESTERDAYS_LOG_DIR does not exist"
else 
  cd /global/tc/log/tcweb-managed-apache-logs/uportal_access_log/$yesterdayYYYY/$yesterdayMM/$yesterdayDD
fi

if [ $RETCODE==0 ] 
then
  #-----------------------------------
  # remove file if already there 
  #-----------------------------------
  if [[ -f $FILE_NAME ]] 
  then
    rm $FILE_NAME
    #echo "remove file"
  fi
fi

#-----------------------------------
# create file and change mode 
#-----------------------------------
if [ $RETCODE==0 ] 
then
  #echo "create file"
  #
  touch $FILE_NAME 
  chmod 777 $FILE_NAME
fi

#-----------------------------------------
# concatenate all files and sort the data 
#-----------------------------------------
cat  * | sort -k 4d,4d -t" " >>$FILE_NAME

#echo $RETCODE_MSG
#return $RETCODE
(nl85@orpheus7)/users/nl85>