Sponsored Content
Top Forums UNIX for Dummies Questions & Answers For loop to check the files availability Post 302588646 by Vijay81 on Monday 9th of January 2012 03:01:27 PM
Old 01-09-2012
For loop to check the files availability

Hi,
I need a help with my script.

Below is my script. What I am doing here is finding the date of the file which I need to process and then finding the list of file names.
Based on the list of file names, check has to be done to see if all the files are there and log the details to a error file.

After finding the SOURCE_FILE_NAME value from the database, I need to check the availability of files, even if one of them is missing, the process has to be failed else it should be success. Check has to be completed for all the files even if one file is missing and then finally log the details and the process should fail.


#!/bin/sh
PHP Code:
date_str=`date "+%Y%m%d%H%M%S"`
errfile=ABC_err_$date_str.log
FileDate
=12212011
echo Script $0 started at `date` >${errfile}
###Check for the Trigger_file
if ! [ -"ABC_Trigger_$FileDate]
then
        
echo "ABC_Trigger_$FileDate doesn't exist" >>${errfile}>&2
Actual_Date
=`ls ABC_Trigger_* | sort -t"_" -k3.8 | head -1 | cut -d"_" -f3`
echo 
$Actual_Date
Date_of_file
=$Actual_Date
echo "ABC_Trigger file is ABC_Trigger_$Date_of_file"
else
Date_of_file=$FileDate
fi
####Connect to DB to get the file name###########
SOURCE_FILE_NAME=`sqlplus -s <<sqlEOF
unageq1/pa23403sw@DEVDB
set feedback off
set heading off
set pagesize 0
set echo off
whenever sqlerror exit failure
whenever oserror exit failure
select SOURCE_FILE_NAME||'_
$Date_of_file' from source_sys_det WHERE Source_sys_name='ABC' ;
sqlEOF
`
echo 
$SOURCE_FILE_NAME

####transposing the file name and creating a file to check if they are available####
awk '$1=$1' RSFS="\n" OFS=, $SOURCE_FILE_NAME >>SOURCE_FILE_NAME_LIST
 
for FILE in $SOURCE_FILE_NAME_LIST
do
if ! [ -
"$FILE]
then
echo "$FILE missing" >>${errfile2>&1
fi
 
done 
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

loop and check

Hi, We are doing a process manually and i am trying to automate it. This is the process. We have a set of files in the directory /temp/d1. the number of files are dynamic. For ex: if i have 5 files i want to compare the chatacters 45-58 of the last line of the first file with the same... (2 Replies)
Discussion started by: dnat
2 Replies

2. Solaris

Check Database availability?

Hi All, My script gets aborted as it is connecting as a remote database through a DB link on every 3rd sunday.As the remote DB is down for more than 6 hours. Can TNSPING DBNAME inside my script ensure the database is up??? Then how can i check the database is up or down ? ... (2 Replies)
Discussion started by: megh
2 Replies

3. Shell Programming and Scripting

Loop check

Hi Gurus I have a recquirement where my loop should work if i have more than 4 listed files in a particular directory. Like the loop in while should continue checking if the directory has more than 4 files and should exit after there are 4 or more files ; if not more than 4 files it should... (5 Replies)
Discussion started by: r_t_1601
5 Replies

4. Shell Programming and Scripting

how to check availability of data of one file in other

hi all i have two files in unix 1.table.name 2.all.tables i need to check the availability of all data of table.name in all.tables.both the table contains n number of data.i need a script which will check one by one whether the data exist in table.name or not.I want this in SH. (1 Reply)
Discussion started by: alisha
1 Replies

5. Shell Programming and Scripting

Script should keep checking for availability of files.

Hi, I want my script to check for availability of few files contineously for some time. Lets say from 10:00 AM to 10:30 AM script should keep checking on a particular location for each file one by one. If all the files are available then only it should complete the next processing part, else... (2 Replies)
Discussion started by: amit.mathur08
2 Replies

6. Shell Programming and Scripting

Check File availability

Hi, I have a task to write a script , which will run everyday to check whether my system has received 2 files from source system. It should mail me ( using mailx preferably ) if the files has not arrived from the source. The scenario is everyday I get 2 files from source system.,... (3 Replies)
Discussion started by: cratercrabs
3 Replies

7. Shell Programming and Scripting

Perl code to check date and check files in particular dir

Hi Experts, I am checking how to get day in Perl. If it is “Monday” I need to process…below is the pseudo code. Can you please prove the code for below condition. if (today=="Monday" ) { while (current_time LESS THAN 9:01 AM) ... (1 Reply)
Discussion started by: ajaypatil_am
1 Replies

8. Shell Programming and Scripting

Check file availability and place flag file

I have to check a directory on Linux (via shell Script which I am trying to build) for about 20 different source files with file patterns and if the files are made available in the directory, I should place flag files for which my other ETL jobs are waiting on to kick off. If the source files are... (6 Replies)
Discussion started by: dhruuv369
6 Replies

9. Shell Programming and Scripting

Check two condition in while loop

Hi, I Have to check two condition in while loop every 2 minutes. while loop is accompanied with number of times it will check.Please help in putting the two condition in while loop as appropriate. z= input value, A=1 while do 1.check the file output,if the file output is N then keep on... (2 Replies)
Discussion started by: netdbaind
2 Replies

10. UNIX for Beginners Questions & Answers

Files availability with count in email

Hi all, we have a requirement , we need to check the files availability in the unix folder and their record counts need to be emailed as attached format Files Count File_1 123 File_2 1898 File_3 29 File_4 456 File_5 123 (2 Replies)
Discussion started by: KK230689
2 Replies
All times are GMT -4. The time now is 02:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy