-1

I have written a script which will run periodically. The program will rename a given file based on complex logic and move it to another folder.

This script would be run by an Oracle Concurrent program who's last run date can be extracted from a database table.

The issue is to extract the file creation date for the file currently in the loop and compare it with last run date of Concurrent Program and only perform actions if the file was created after last run timestamp of the concurrent program.

I have also given code for my shell script for better understanding : https://pastebin.com/6P52BYP3

I'm facing issues in extracting creation timestamp for a given file and comparing it with last run date of program.

Thanks, Shubham

Shubham Gupta
  • 369
  • 1
  • 4
  • 15

2 Answers2

0

You can extract the creation time with the stat command.

Eg on OSX:

$ stat -f "%B" a_file
1491371944

%B is time in seconds since epoch when the inode was born.

Some versions of stat would work like this:

# stat --format=%Z file
1491073904

%Z is time of last change in seconds since Epoch.

I can't see a creation date option on solaris.

John C
  • 4,276
  • 2
  • 17
  • 28
0

This is how I achieved the solution :

l_file_date=stat -c %y $l_fileinput | cut -d'.' -f1

l_program_date=sqlplus -s $FCP_LOGIN <<EOF
    set pagesize 0;
    SELECT *
        FROM (  SELECT TO_CHAR (fcr.request_date, 'yyyy-mm-dd hh24:mi:ss')
                FROM fnd_concurrent_requests fcr, fnd_concurrent_programs fcpt
                WHERE     fcpt.concurrent_program_id = fcr.concurrent_program_id
                        AND fcpt.concurrent_program_name = 'XXEFTFILENAMECHANGE'
                        AND fcr.phase_code = 'C'
                        AND fcr.status_code = 'C'
            ORDER BY request_date DESC)
        WHERE ROWNUM = 1;
    EXIT;
EOF

l_file_date_u=$(date -d "$l_file_date" "+%s")

l_program_date_u=$(date -d "$l_program_date" "+%s")

if expr "$l_file_date_u" ">=" "$l_program_date_u" > /dev/null; then

<CODE>

fi
David C. Rankin
  • 81,885
  • 6
  • 58
  • 85
Shubham Gupta
  • 369
  • 1
  • 4
  • 15