Sponsored Content
Top Forums Shell Programming and Scripting Help with a shell script for creating a log file Post 302096091 by heprox on Tuesday 14th of November 2006 01:00:58 AM
Old 11-14-2006
Question

I ended up using something similar with:

Code:
#!/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:

Code:
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.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help on creating shell script

Can some one smart here help I need to create a shell script that does this below using vi editor. decrypts a file (specified as an argument to the script) containing text which was encrypted using the ROT-13 algorithm. The decrypted text should be written to a new file leaving the input file... (1 Reply)
Discussion started by: master_6ez
1 Replies

2. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

3. Shell Programming and Scripting

how to execute ksh simple shell script without creating .sh file

please help me to execute a simple shell script like for i in `ls echo $i done . i dont want to create a new sh file to execute it. Can i just type and execute it ? because I always this kind of simple for loops . Please help . Thanks (7 Replies)
Discussion started by: Sooraj_Linux
7 Replies

4. Shell Programming and Scripting

Shell script for creating log file and sending mail?

Hi , I am trying to create shell script which will help me to compare file name in two folder. There is a multiple file store in 2 folder.I want to compare that with the name. If all the file are same then send a mail that "all date is same" if not then create one log file which contain... (4 Replies)
Discussion started by: san_dy123
4 Replies

5. Shell Programming and Scripting

Creating a Continuous File Reading-Executing Shell Script

I need to write something that will read and execute all the files(Mainly executable scripts) inside one or more folders; in other words, a continuous chain with a break when finished. I'm new to shell and need syntax help. I'm on Ubuntu 12.10-Gnome btw. Here are some main highlights I think... (2 Replies)
Discussion started by: linuxlololol
2 Replies

6. Shell Programming and Scripting

Creating new users using a text file as imput (using only shell script and/or awk)

I need somebody who could help with an exercise. You have a text file called users.txt with this info inside: users.txt: user1:1234:/home/homedir1 ; user2:1234:/home/homedir2 ; user3:1234:/home/homedir3 ; user4:1234:/home/homedir4 ; The script should create an user using the... (2 Replies)
Discussion started by: marcosruiz
2 Replies

7. Shell Programming and Scripting

Creating IN list in PLSQL script dynamically by using shell script

Hi all, I have a PLSQL script which has a IN list where it takes some ids as input. For example SELECT * FROM EMPLOYEE WHERE EMPLOYEE_ID IN (comma separated list ) I want to run this quest inside a shell script but I would like to prepare the IN list dynamically where the employee ids... (1 Reply)
Discussion started by: LoneRanger
1 Replies

8. Shell Programming and Scripting

Shell Script function to use script name for log file output

Hi Team - I"m very new to Shell Scripting so I have a rather novice question. My forte is Windows Batch Scripting so I was just wondering what the Shell Script equivalent is to the DOS command %~n? %~n is a DOS variable that dispayed the script name. For instance (in DOS): REM... (11 Replies)
Discussion started by: SIMMS7400
11 Replies

9. Shell Programming and Scripting

Parsing a log file and creating a report script

The log file is huge and lot of information, i would like to parse and make a report . below is the log file looks like: REPORT DATE: Mon Aug 10 04:16:17 CDT 2017 SYSTEN VER: v1.3.0.9 TERMINAL TYPE: prod SYSTEM: nb11cu51 UPTIME: 04:16AM up 182 days 57 mins min MODEL, TYPE, and SN:... (8 Replies)
Discussion started by: amir07
8 Replies

10. Shell Programming and Scripting

Creating an excel file with filters using shell script.

Hi All, I am new to shell scripting. I have made a script that can convert an excel file from cvs file. This excel file contains hundreds of records and i would like the reader to be able to filter. Is it possible to create an excel file with filters? or that functionality has not been... (3 Replies)
Discussion started by: Marvin159875321
3 Replies
All times are GMT -4. The time now is 02:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy