I have a schell script that runs continously on an AIX system. It is actually started from another shell script with the "ksh -x" command and then I just write the output to a log file. This causes the log files to be filled with mostly useless information. I would like to modify this script to create its own log file internally and then be able to just have it log select acitivity. The script looks like:
#!/bin/ksh
PATH=/gers/nurev/menu/pub/sbin:/gers/nurev/menu/pub/bin:/gers/nurev/menu/pub/mac
:/gers/nurev/menu/adm/sbin:/gers/nurev/menu/adm/bin:/gers/nurev/menu/adm/mac:/ge
rs/nurev/custom:/gers/nurev/fix:/gers/nurev/src_rev/fix:/gers/nurev/opt/path:/ge
rs/nurev/bin:/g/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/sbin:.
ORACLE_HOME=/gers/nurev
ORACLE_SID=nurev
export PATH
export ORACLE_HOME
export ORACLE_SID
#
# Function : is_file_arrived file
# Arg(s) : file = file to verify
# Output : None
# Status : 0 = yes file arrived, 1 = no
# Env. : IFA_WAIT : interval (secs) for file size check (def=5)
#
is_file_arrived() {
[ -z "$1" ] && return 1
local file=$1
local arrived=1
local size1 size2
if [ -f "$file" -a -z "$(fuser $file 2> /dev/null)" ] ; then
size1=$(ls -l $file 2>/dev/null | awk '{print $5}')
sleep ${IFA_WAIT:-15}
size2=$(ls -l $file 2>/dev/null | awk '{print $5}')
[ ${size1:-1} -eq ${size2:-2} ] && arrived=0
fi
return $arrived
}
processFile ()
{
local fileName=$1
local fileExtension=$2
local fileNewName="/gers/nurev/datafiles/str${fileExtension}.asc"
local filePrintPath="/gers/nurev/print"
local fileTmpPath="/gers/nurev/tmp"
local fileODIName="str${fileExtension}.pos"
mv -Eignore $fileName $fileNewName
prepup $fileNewName $fileExtension
mv -Eignore $filePrintPath/$fileODIName $fileTmpPath/$fileODIName
save2tmp $fileExtension
call_siu $fileExtension ###I'd like to add when this command is run and the $fileExtension given date/time
}
# Main Processing
nsec=1
while [[ "$(date +%H%M)" -lt 2329 ]]
do
for fileName in /gers/nurev/datafiles/[Uu][Pp][Ll][Oo][Aa][Dd].[0-9][0-9][0-9
][0-9] ###I'd like to log when a file is found with date/time
do
fileExtension=${fileName#*.}
is_file_arrived "$fileName" && nsec=1 && processFile $fileName $fileExtens
ion
done
sleep $nsec
case $nsec in
1) nsec=15;;
15) nsec=45;;
45) nsec=90;;
90) nsec=300;;
300) nsec=600;;
600) nsec=900;;
*) nsec=1800;;
esac
done
...the log file should just have a variable declared about the logfile name and path. Is there a way to create a function to write the log entry and then I could just call the function and hand it a parameter that would be the log entry? Say something like "LOG(0002 processed at 11-11-06/12:00)"?
#!/bin/ksh
######### Environment Setup #########
PATH=/gers/nurev/menu/pub/sbin:/gers/nurev/menu/pub/bin:/gers/nurev/menu/pub/mac
:/gers/nurev/menu/adm/sbin:/gers/nurev/menu/adm/bin:/gers/nurev/menu/adm/mac:/ge
rs/nurev/custom:/gers/nurev/fix:/gers/nurev/src_rev/fix:/gers/nurev/opt/path:/ge
rs/nurev/bin:/g/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/sbin:.
ORACLE_HOME=/gers/nurev
ORACLE_SID=nurev
export PATH
export ORACLE_HOME
export ORACLE_SID
########## Global Variables ##########
DATE=$(date +%m%d%y)
TIME=$(date +%H%M)
DatafilesDir="/gers/nurev/datafiles"
PrintDir="/gers/nurev/print"
TempDir="/gers/nurev/tmp"
Logfile="/tmp/test_str_process_$DATE.log"
########## Function to Verify File is Completely Uploaded ###########
# Function : is_file_arrived file
# Arg(s) : file = file to verify
# Output : None
# Status : 0 = yes file arrived, 1 = no
# Env. : IFA_WAIT : interval (secs) for file size check (def=5)
#
is_file_arrived() {
[ -z "$1" ] && return 1
local file=$1
local arrived=1
local size1 size2
if [ -f "$file" -a -z "$(fuser $file 2> /dev/null)" ] ; then
size1=$(ls -l $file 2>/dev/null | awk '{print $5}')
sleep ${IFA_WAIT:-15}
size2=$(ls -l $file 2>/dev/null | awk '{print $5}')
[ ${size1:-1} -eq ${size2:-2} ] && arrived=0
else
log_it "Store file $file not done uploading at $TIME on $DATE"
fi
return $arrived
}
######### GERS Processing of File ###########
processFile ()
{
local fileName=$1
local fileExtension=$2
local fileNewName="$DatafilesDir/str${fileExtension}.asc"
local fileODIName="str${fileExtension}.pos"
log_it "File to be processed is $fileName"
mv -Eignore $fileName $fileNewName
prepup $fileNewName $fileExtension
mv -Eignore $PrintDir/$fileODIName $TempDir/$fileODIName
save2tmp $fileExtension
call_siu $fileExtension
log_it "Store file $fileName processed at $TIME on $DATE"
}
########## Log File Function ###########
log_it()
{
printf "%s\n" "$*" >> "$Logfile"
}
########## Main Processing ###########
nsec=1
while [[ "$(date +%H%M)" -lt 2340 ]]
do
for fileName in $DatafilesDir/[Uu][Pp][Ll][Oo][Aa][Dd].[0-9][0-9][0-9][0-9]
do
fileExtension=${fileName#*.}
is_file_arrived "$fileName" && nsec=1 && processFile $fileName $fileExtens
ion
done
sleep $nsec
case $nsec in
1) nsec=15;;
15) nsec=45;;
45) nsec=90;;
90) nsec=300;;
300) nsec=600;;
*) nsec=900;;
esac
done
...the log file actually looks like:
File to be processed is /gers/nurev/datafiles/upload.0027
Store file /gers/nurev/datafiles/upload.0027 processed at 2158 on 111306
File to be processed is /gers/nurev/datafiles/upload.0028
Store file /gers/nurev/datafiles/upload.0028 processed at 2158 on 111306
Store file /gers/nurev/datafiles/[Uu][Pp][Ll][Oo][Aa][Dd].[0-9][0-9][0-9][0-9] n
ot done uploading at 2158 on 111306
Store file /gers/nurev/datafiles/[Uu][Pp][Ll][Oo][Aa][Dd].[0-9][0-9][0-9][0-9] n
ot done uploading at 2158 on 111306
...what I don't get is why I'm still getting the entries for when it doesn't find an "upload.####" file in the log. I want it to only write an entry to the log if it finds a matching file and sends it off to be processed.