Monitoring for specific date stamped files before and after midnight


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Monitoring for specific date stamped files before and after midnight
# 1  
Old 04-03-2013
Monitoring for specific date stamped files before and after midnight

Hi Guys,

I am having a brain freeze....

I want to monitor a directory for a time stamped file on a sol 10 system in bash or ksh, the files will come in looking like this..

randomfile.DDMMYY.rpt

The problem i am having is the file can come in before or after midnight, the file will come in with the pre midnight date even if it comes in after mid night but i can't think what variable to use as my date, e.g
if i use

DAY=`TZ=CST+24 date '+%d%m%y'` this works fine if the script runs after midnight, but if its before midnight it's looking for the wrong date...and i need this script to monitor before and after midnight for specific files.......also there are older versions of up to 7 days of the files i'm looking for.

I'm guessing i need to some how check the time to use what variable to use? I'm sure there has to be a better way to do it.
Any suggestions would help.....in my head this seems so easy to do, but my brain is sat in the corner reading the paper giving me rude hand gestures.
# 2  
Old 04-03-2013
Just playing around, as least on my linux computer, is this what you're looking for?
Code:
$ TZ=CST+24 date '+%d%m%y' --date=today
020413
$ TZ=CST+24 date '+%d%m%y' --date=yesterday
010413

This User Gave Thanks to hanson44 For This Post:
# 3  
Old 04-03-2013
Thanks for the reply. My network connection just went boom so I can't really look until I log back in. I just need it to Monitor a directory for files say randomfile.030413 and then after midnight still look for randomfile.030413. So I need away to change the variable after midnight? There is maybe a better solution than the approach I'm using or your idea fits?
# 4  
Old 04-03-2013
I think my idea probably fits. I think something like this will likely work in a shell script:
Code:
    today=`TZ=CST+24 date '+%d%m%y' --date=today`
yesterday=`TZ=CST+24 date '+%d%m%y' --date=yesterday`
     hour=`TZ=CST+24 date '+%H' --date=today`

expected_file=randomfile.$today.rpt
if [ -f $expected_file ]; then
  echo Found expected file from today: $expected_file
  # Process the file
fi

expected_file=randomfile.$yesterday.rpt
if [ -f $expected_file -a $hour -le 2 ]; then
  echo Found expected file from yesterday: $expected_file
  echo Must have slid in just before midnight
  # Process the file
fi

This User Gave Thanks to hanson44 For This Post:
# 5  
Old 04-03-2013
Great i am seeing your approach, at first glance this could work, but i do also have files from the last seven days in the directory so i need to make sure i do it so i dont detect a file from 2 days back :P thanks so much for the answer it has got my brain back into gear for sure. Smilie
# 6  
Old 04-03-2013
Yes, because you have a good system set up for naming the files, with the DDMMYY section, the old files, like the ones two days old, will be ignored. And once the day gets going, the script will ignore files from the previous day, depending on how you test for the $hour variable and how often the script runs.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find all files modified from midnight (i.e. from midnight (00:00:00)) of current date?

Hi there! I was wondering if someone could help me with the following: I'm trying to find all files within a directory which have been modified since midnight of the current date. Any help would be appreciated. Thank you kindly. (6 Replies)
Discussion started by: Jimmy_the_tulip
6 Replies

2. Shell Programming and Scripting

Find files for a specific date

Hi, I am looking to find files of a specific date. I am on Sun Solaris so newermt doesnot work.. I thought of using mtime but not getting how to use it. Please help me with this.. Regards Abhinav (3 Replies)
Discussion started by: abhi1988sri
3 Replies

3. Shell Programming and Scripting

Find files with specific date

Dear all, kindly i have some files with different dates i need to grep word from these files but i need to search in files with date 2012-12-02 not all files in this directory do u have any command (4 Replies)
Discussion started by: maxim42
4 Replies

4. UNIX Desktop Questions & Answers

How to delete files from a specific date?

Guys, I am wondering how to remove files for a specific date in a directory? for instance when I do ls -l , i see many files. And i want to delete files for date May 15: 58252015 May 10 03:45 my_05102012.log 58252015 May 15 06:45 my_05152012.log Thanks (8 Replies)
Discussion started by: DallasT
8 Replies

5. Shell Programming and Scripting

Monitoring specific string or keyword in rotating log files.

Hi there, I like to ask how i shall monitor specific string or keyword in rotating log files. e.g. I have at 10 rotating logfiles. I use the command below to grep the string, but eventually become non functional because the logfile rotates and new logfile is active. tail -f <logfile1> |grep... (1 Reply)
Discussion started by: shtobias
1 Replies

6. UNIX for Dummies Questions & Answers

Monitoring specific files and folders

I want a mechanism to monitor a folder full of files that are sensitive. I want to log all accesses,modifications and changes to any file within the folder in a log file which should give me access/modify/change times,the user id of the process which tried and the pid. Even some idea of what to... (1 Reply)
Discussion started by: Vivek788
1 Replies

7. Filesystems, Disks and Memory

backup of files for a specific date

In Linux Advance server I want to write one script for backing up files for a specific date like 24/07/2008. (3 Replies)
Discussion started by: akm9999
3 Replies

8. Shell Programming and Scripting

backup of files for a specific date

I want to write script for backing up archive logs files for specific date. please give me idea for that. (2 Replies)
Discussion started by: akm9999
2 Replies

9. Solaris

List files with a specific date...

Hi all, thanks in advance for reading and anyposts... I was wondering if its possible to find all files in a directory with a specific date. I know I can do: but that will only give a list of files greater than todays date... Any ideas? Thanks, Marky Mark... (4 Replies)
Discussion started by: B14speedfreak
4 Replies

10. Programming

problem deleting date-time stamped file in a directory

I have a number of files of the format filename.xfr_mmddyy_%H%M%S which i get in a specified directory daily. Now i want to search in the specified directory & delete the files which are more than 2 days old .So I use a command find $DIR/backup/* -ctime +2 -exec rm -f {} \; But after executing... (1 Reply)
Discussion started by: dharmesht
1 Replies
Login or Register to Ask a Question