The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To create alist of files created in the last 1 hour. Asheesh UNIX for Dummies Questions & Answers 4 02-14-2008 11:56 AM
Kill a particular process if it's over an hour hold xgringo SUN Solaris 9 12-11-2007 01:18 PM
display the files in a folder which are older than 1 hour vgs Shell Programming and Scripting 7 05-29-2007 03:05 PM
display the files in a folder which are older than 1 hour vgs UNIX for Dummies Questions & Answers 3 05-25-2007 09:46 PM
Reference Variables To A Child Process Created With Fork AJAY BHATIA High Level Programming 2 10-07-2001 09:41 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-14-2005
negixx negixx is offline
Registered User
  
 

Join Date: Jun 2005
Location: St. Louis, MO
Posts: 32
Question Need to process files created an hour ago

Hello all,

I would like to ask for an advice on how to deal with the following scenario.

Every now and then, our ERP system creates an interface text file with the following file format - XORD????.DLD where ???? is a sequence number. We can have 1 or more XORD files created in an hour. Now, I would like to create a script that is run every hour to check XORD* created for the last hour and then verify its contents. How do I approach this using scripting (ksh). The first thing that comes into my mind is to save the result of `ls -lt XORD` to a text file and then sort it but not sure how to compare the time stamp with the current time. Thank you very much

Sample listing of files, say if I run my script now, I wont get anything......

-rw-rw-rw- 1 amcgraw dba 5609 Jun 14 07:17 XORD9306.DLD
-rw-rw-rw- 1 root sys 172859 Jun 14 00:22 XORD9305.DLD
-rw-rw-rw- 1 ldowning dba 7287 Jun 13 17:24 XORD9304.DLD
-rw-rw-rw- 1 root sys 39985 Jun 13 17:05 XORD9303.DLD
-rw-rw-rw- 1 swelch dba 1427 Jun 13 16:20 XORD9302.DLD
-rw-rw-rw- 1 athomas dba 1207 Jun 13 16:09 XORD9301.DLD
-rw-rw-rw- 1 shicks dba 73610 Jun 13 16:07 XORD9300.DLD
-rw-rw-rw- 1 kscott dba 9860 Jun 13 15:52 XORD9299.DLD
-rw-rw-rw- 1 jrobinso dba 2404 Jun 13 15:28 XORD9298.DLD
-rw-rw-rw- 1 dburke dba 2436 Jun 13 14:48 XORD9297.DLD
-rw-rw-rw- 1 srainwat dba 1936 Jun 13 14:26 XORD9296.DLD
-rw-rw-rw- 1 kscott dba 8829 Jun 13 14:18 XORD9295.DLD
-rw-rw-rw- 1 mgwaltne dba 2532 Jun 13 13:57 XORD9294.DLD
-rw-rw-rw- 1 nthackre dba 2754 Jun 13 13:47 XORD9293.DLD
-rw-rw-rw- 1 dburke dba 2186 Jun 13 13:29 XORD9292.DLD
-rw-rw-rw- 1 shicks dba 6543 Jun 13 13:27 XORD9291.DLD
-rw-rw-rw- 1 dburke dba 62840 Jun 13 12:34 XORD9290.DLD
-rw-rw-rw- 1 shicks dba 75595 Jun 13 11:55 XORD9289.DLD

Joseph
  #2 (permalink)  
Old 06-14-2005
jhansrod jhansrod is offline
Registered User
  
 

Join Date: May 2005
Posts: 80
Hi Joseph

Can the file name change once you have processed it ? if so, just rename the file to a name that has a extension of the time inclusive of second it was run.

J
  #3 (permalink)  
Old 06-14-2005
negixx negixx is offline
Registered User
  
 

Join Date: Jun 2005
Location: St. Louis, MO
Posts: 32
Thanks J.

The file name cannot change after processing that is why i have to depend on the `ls` information.
  #4 (permalink)  
Old 06-15-2005
negixx negixx is offline
Registered User
  
 

Join Date: Jun 2005
Location: St. Louis, MO
Posts: 32
Any help is much appreciated...please.
  #5 (permalink)  
Old 06-15-2005
pixelbeat pixelbeat is offline
Registered User
  
 

Join Date: Jun 2005
Location: Ireland
Posts: 61
On each run `touch timestamp_file`
Then you can `find -newer timestamp_file`

You haven't given enough info but here is some
bash to process each new file seperately,
assuming all the files are in 1 directory:

Code:
#!/bin/sh

WORK_DIR=/var/reports
TSF=/tmp/batch_process.timestamp

[ ! -e $TSF ] && touch -r $WORK_DIR $TSF

find $WORK_DIR -newer $TSF -type f -maxdepth 1 |
while read REPORT; do
    echo processing $REPORT
done

touch $TSF
  #6 (permalink)  
Old 06-15-2005
negixx negixx is offline
Registered User
  
 

Join Date: Jun 2005
Location: St. Louis, MO
Posts: 32
Thanks!

The files are only created in one directory and all files starts with XORD. These files are created anytime within the hour and every top of the hour, I would like to check all XORD files created the last hour on the time my script run (thru cron).

Say if my script runs at 3:00PM, I would like to get the list of XORD files created between 2:00-2:59PM and then put it in a variable so I can check each file if the contents are correct.

I tried using the find command using option -ctime, atime and mtime but this is by the day and sometimes the results is not consistent (or maybe I am not using it or understand it correctly...)

THanks!

Joseph
  #7 (permalink)  
Old 06-15-2005
pixelbeat pixelbeat is offline
Registered User
  
 

Join Date: Jun 2005
Location: Ireland
Posts: 61
The timestamp option should work, and be more general.
The hourly period is just determined/configured in cron.
If you do want to have problematic edge cases where
you may miss files or process files twice, then use the following:

find $WORK_DIR -mmin -60 -type f -name "XORD*" -maxdepth 1
Closed Thread

Bookmarks

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0