Operating System - HP-UX
1748080 Members
5068 Online
108758 Solutions
New Discussion юеВ

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

 
Suman_7
Frequent Advisor

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

All,

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.


Example:

Database date 20040312

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

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
Suman



Thanks a lot!

Suman
3 REPLIES 3
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.

HTH
mark
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

Hi
This can be done by a simple touch and find commands

with the date you get from database

Goto the directory
touch CCYYMMDDHHMMSS sample
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