Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Showing results for 
Search instead for 
Did you mean: 

Get the file names from a directory and run in a loop

Frequent Advisor

Get the file names from a directory and run in a loop


I have a requirement in which the users want to get the date parameter (YYYYMMDD) format from database table and go to a remote server and look for any file name that are >= that date. The file name is in the format file_name_YYYYMMDD. The program has to pass the date protion of the filename (YYYYMMDD) as a parameter and execute in a loop for all the available files that are >= (YYYYMMDD) date.


Database date 20040312

Go to directory and look for any file that is >=20040312.
Example file_name_20040312

The program has to execute the in built shell script with the 3 date parameter in a loop

first execute run_load(20040312)
Then execute run_load(20040313)
Then execute run_load(20040314)

One more question.

How do I make the script to execute after every 30 mins to look for a file on the server till 11:45 AM.


Thanks a lot!

Mark Greene_1
Honored Contributor

Re: Get the file names from a directory and run in a loop

To answer your last question first, you can create an entry in the crontab for the Login ID under which you want the process to run, which would look something like this:

15,45 6,7,8,9,10,11 * * * /full/path/name/

which will run at 15 and 45 minutes past the hour from 6am to 11am. The "/full/path/name/" is the complete directroy path and file name of the script.

For the first question, you need to take the date given and calculate how many days back from today that is. Some one had a script that would give julian dates, I'll see if I can find it. If you convert today's date to julian and the database date to Julian, then it's simple subtraction to get the delta which you use in a "find" command:

find / -mtime "$DAY_BACK" -print

where $DAY_BACK is the difference calculated from today and the database date.

the future will be a lot like now, only later
Nicolas Dumeige
Esteemed Contributor

Re: Get the file names from a directory and run in a loop

To increase the date, you can do it in Oracle :

select sydate, sysdate+1, sysdate+2 from dual;

with ALTER SESSION SET NLS_DATE_FORMAT='RRRRMMDD' or using to_char function to get the date formatting suiting your need.

As for the call of the shell, you can do it from SQL*Plus with the host() function or using !
All different, all Unix
Sathish C
Frequent Advisor

Re: Get the file names from a directory and run in a loop

This can be done by a simple touch and find commands

with the date you get from database

Goto the directory
find . -name "*" -type f -newer sample
will five you all the files that were created after the date you passed .

so you make this as a function and call it as many time as you need it .
Some cause happiness wherever they go; others, whenever they go