Check existence of a number of files and call other scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check existence of a number of files and call other scripts
# 1  
Old 03-26-2011
Question Check existence of a number of files and call other scripts

Hi,
I am new to unix scripting and am jus getting to learn about it..
I need to know on how to check for the existence of a number of files in a path..i.e the files are ftp'ed from several other servers, should check if all the files have arrived, if not wait till they arrive..can i use a flag here to have a count on the number of file arrived? if yes, please let me know..once all the files have arrived..should call other scripts for execution which are to be sequentially executed..please help me on this!
# 2  
Old 03-26-2011
Hi yohasini,

* I'm not sure if you have the total number of files to be transfered, if yes, try with:

Code:
files=$(find . -type f | wc -l)

if [ $files -eq 221 ] # total number of files for this example = 221
then
echo "Total # of files = $files, ftp tranfer is completed"
./yourscript1.sh
./yourscript2.sh
.
.
else
echo "Wait, only $files files transfered, $[221-$files] files pending to be received"
fi


You have to verify (send this "if" script) manually, if you need to have a continuous verification, a cron job
would be necessary to send it every certain periods.

Hope it helps,

Regards

Last edited by cgkmal; 03-26-2011 at 05:53 AM..
# 3  
Old 03-26-2011
Hi kamal,
thanks for the info..but what if i 'd want to check if particularly named files say "newfile.servername_date.dat" have been ftp'ed in the particular folder. and i am aware of the number of files, they are 16.
# 4  
Old 03-26-2011
Quote:
Originally Posted by yohasini
Hi kamal,
thanks for the info..but what if i 'd want to check if particularly named files say "newfile.servername_date.dat" have been ftp'ed in the particular folder. and i am aware of the number of files, they are 16.
Hi yohasini,

Then you can add "-name..." to specify the type of files as follow:
Code:
files=$(find . -type f -name '*.*_*.dat' | wc -l)

if [ $files -eq 16 ]
then
echo "Total # of files = $files, ftp tranfer is completed"
./yourscript1.sh
./yourscript2.sh
.
.
else
echo "Wait, only $files files transfered, $[16-$files] files pending to be received"
fi

If the format is fixed as you say "newfile.servername_date.dat" use the regex *.*_*.dat as above, if not you can use only *.dat.

Regards.
# 5  
Old 03-29-2011
Yes kamal. The name of the flat file would be something like OBJ_FULL.servername.date(i.e every sunday's date(2011-3-20)).dat). How do i pull off the latest files of this kind from this folder? how do i incorporate it with find?
# 6  
Old 03-29-2011
Quote:
Originally Posted by yohasini
Yes kamal. The name of the flat file would be something like OBJ_FULL.servername.date(i.e every sunday's date(2011-3-20)).dat). How do i pull off the latest files of this kind from this folder? how do i incorporate it with find?
Hi yohasini,

To find the latest files of this kind, you need to specify which latest files, I mean, files older than 1 day, files older than 1 year, etc. See next example info:
Code:
# 1-) Looking for *_*.* files older than 365 days and printing them within folder and subfolder
 find . -name '*_*.*.dat' -mtime +365

# 2-) Printing *_*.* files files modified less than 365 days ago within folder and subfolders
 find . -name '*_*.*.dat' -mtime -365

# 3-) Printing *_*.* files files modified 365 days ago within folder and subfolders
 find . -name '*_*.*.dat' -mtime 365

About -mtime: (-mtime n)
(+) means greater than, (-) means less than, and without any symbol means exactly equal to.

Another example:
Code:
#Looking files of kind "*_*.*.dat" modified less than 60 days ago
find . -type f -name '*_*.*.dat' -mtime -60 
./OBJ_FULL.servername1.2011-02-13.dat

#Looking files of kind "*_*.*.dat" modified less than 70 days ago
 find . -type f -name '*_*.*.dat' -mtime -70
./OBJ_FULL.servername.2011-01-22.dat
./OBJ_FULL.servername1.2011-02-13.dat

Only replace the find command in the script with the find command you need with -mtime option you want.
Code:
files=$(find . -type f -name '*_*.*.dat' -mtime -70 | wc -l)


Hope it helps,

Regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to check the files existence inside a directory.

Hello Folks, On Below Script, I want to apply condition. Condition that it check the directory for files if not found keep checking. Once directory have files and founded do the calculation and finish the code. Script to check the files existence inside a directory, If not then keep... (16 Replies)
Discussion started by: sadique.manzar
16 Replies

2. Shell Programming and Scripting

Check the Files existence

Hi I have a requirement to check whether the files exists, then it will call other steps in shell script. I did ls *.csv|wc -l if then checking the count of the files should be more than 1 then it will call other steps. I am getting the error that too many arguements as there n... (13 Replies)
Discussion started by: cnrj
13 Replies

3. Shell Programming and Scripting

Check for the existence and add them from 2 different files

Hi, I have two files file1: ALEX DANY GARY TOM MARY HARRIS file2: ALEX 3 ALEX 5 ALEX 0 ALEX 1 ALEX 0 DANY 2 (2 Replies)
Discussion started by: Diya123
2 Replies

4. Shell Programming and Scripting

check existence of files in a folder

Hi I am having a problem to verify existence of files. I need to know whether or not files in a folder that begins with a name. For example all files that start with The_File_ *. I was doing it this way, but gives me error. if text -f /work/The_File_* then ... else .. fi (5 Replies)
Discussion started by: Rodrih92
5 Replies

5. Shell Programming and Scripting

KSH - How to call different scripts from master scripts based on a column in an Oracle table

Dear Members, I have a table REQUESTS in Oracle which has an attribute REQUEST_ACTION. The entries in REQUEST_ACTION are like, ME, MD, ND, NE etc. I would like to create a script which will will call other scripts based on the request action. Can we directly read from the REQUEST_ACTION... (2 Replies)
Discussion started by: Yoodit
2 Replies

6. Shell Programming and Scripting

How to check for file existence?

i want to check if the file is in the directory or not, and also it should be handle error conditions, like missing files and report the error and exit. i did something like this: file ="hello" if !test -e "${file}" then echo "No such files exist!" exit 1 else do something....... fi ... (1 Reply)
Discussion started by: mingming88
1 Replies

7. Shell Programming and Scripting

1 script or multiple scripts?? - check files, run jobs

Question for anyone that might be able to help: My objective is to eheck if a file (a source file) exists in a directory. If it does then, I'd like to call an application (Informatica ETL file...not necessary to know) to run a program which extracts data and loads it into multiple targets. ... (6 Replies)
Discussion started by: jnanasakti
6 Replies

8. AIX

Check for File Existence

I have requirement where i need to search for files which start with SALESORDER and PURCHASEORDER. i need to process the files with SALESORDER first and then PURCHASEORDER. If SALESORDER files are not there i dont want to process PURCHASEORDER and i want to come out of script. I have written a code... (4 Replies)
Discussion started by: dsdev_123
4 Replies

9. UNIX for Dummies Questions & Answers

Variable check for existence ?

Hi , I have a script wherein i have a For Loop. Within this for loop i create a variable and assign it a value. The script goes to a For Loop only if certain conditions are met , which means the variable may or may not exists. However down the line in the script i have to check if that... (2 Replies)
Discussion started by: samit_9999
2 Replies

10. Shell Programming and Scripting

check for FILES existence

hi, I have a list of filenames and I want to verify if they all exist. I know "if filename" would do the trick but how do I go about a list of files? thanks (3 Replies)
Discussion started by: mpang_
3 Replies
Login or Register to Ask a Question