check for new file over 24 hrs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting check for new file over 24 hrs
# 1  
Old 09-02-2008
check for new file over 24 hrs

Hi all,
I am trying to figure out a method to flag an error if a file has not arrived in a certain directory within 24 hrs of the last one arriving.
I am currently writing the time to a file when a file is recieved. I then want to check for a new file reguarly but flag an error if it has been over 24 hrs since a file was received. However i cannot work out how to test for a 24 hour period as the script will be run at irregular intervals.
Any ideas?

Thanks
# 2  
Old 09-02-2008
time_diff (){
start_mins=`echo "$1"|awk -F":" '{print $1*60+$2}'`
end_mins=`echo "$2"|awk -F":" '{print $1*60+$2}'`
((elapsed_mins = $end_mins - $start_mins))

if [ "$elapsed_mins" -lt 0 ]
then
((elapsed_mins += 1440))
fi

if [ "$elapsed_mins" -gt 59 ]
then
print $((elapsed_mins / 60))
fi
}

last_time=`ls -lrt|tail -1|awk '{print $8}'`
curr_time=`date "+%k:%m"`
time_diffrence=`time_diff $last_time $curr_time`

if [ "$time_diffrence" -lt "24 ]
then
do whatever you want
fi
# 3  
Old 09-02-2008
or simply you can use find command to see whether you have any file which is older than 24 hrs..
# 4  
Old 09-02-2008
You can jsut use the find command to handle this...


Code:
find directory -name "filename" -type f -mtime -1

or
Code:
find directory -name "filename" -type f -mmin -1440

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check if file got created in less than 10 hrs

Dear Gurus, I want to check if file got created in less than 10 hrs in .ksh. Here is my requirement In $var5 : I'm storing file name In $var4 I have stored : select to_char(sysdate,'YYYYMMDDHH:MM:SS') from dual; If that file date time is less than 10 hrs, then I need to check if less... (1 Reply)
Discussion started by: thummi9090
1 Replies

2. Shell Programming and Scripting

finding files N hrs old

I know you can supply the find command with an option to find files > than N days old. Is there some way to do this to find files that are > than N hours old. I want to do somthing like this: find . -mtime + (now - 2hrs) -print If not is there a way to do this with sed or awk or some... (5 Replies)
Discussion started by: BeefStu
5 Replies

3. Shell Programming and Scripting

To delete files older than 24 hrs

I have to retain only 1 day files in my system an I have to delete all the other files which are older than 24 hrs. Please let me know the option I have to give in the find -mtime command. (3 Replies)
Discussion started by: rajesh8s
3 Replies

4. Shell Programming and Scripting

List last 10 Hrs file and find error files

Hi, I need a script that can search a word "Error" in last 10 Hrs generated logs in /log/App1 and /log/App2 folder.. Note these directories have massive log files ...actually our application generate 100 Log files of size 2MB in just a min so script must be fast enough to cater this I... (9 Replies)
Discussion started by: Mujtaba khan
9 Replies

5. UNIX for Dummies Questions & Answers

How to list files Created in last 2 hrs

I wanted to know what command should I use to see the files created in last 2 hours in a given directory. I know to see the files changed in last one day I can use this: find /admin//dump -type f -ctime -1 -print | xargs ls -lt|pg However I am not getting what should I use if I wanted tol... (4 Replies)
Discussion started by: rsonakiya
4 Replies

6. Shell Programming and Scripting

search for a file, if not found sleep and repeat it for 3 hrs

Hi, Can someone help me with this script .... I need a ksh script, which will search for a specific file in a directory, if file not found sleep for 10 mins and search again, if still not found sleep again for 10 mins and so on .... it should search for that file for 3 hours and if that file... (5 Replies)
Discussion started by: santosham
5 Replies

7. Shell Programming and Scripting

Shell script is taking more than 3 hrs to execute

Hi I am doing a process of converting all the values of key column into a row, for eg Key col1 col2 1 1 1 1 2 1 1 1 3 1 3 1 2 ... (2 Replies)
Discussion started by: nvuradi
2 Replies

8. SuSE

Time resetting to 00 HRS on starting

I Have a SUSE Linux Enterprise server 9.0. When I start the server , using date command I daily find that the time it is showing is 00.00 Hrs. It shows the date correctly. Every day I have to set the time using the date command. I am facing this proble from last 3 weeks but couldn't find a... (4 Replies)
Discussion started by: V.V.KUMAR
4 Replies

9. Shell Programming and Scripting

modifying grep to get files only within last 2 hrs

Hi gurus I am currently using the below mentioned grep to find timestamp of last generated log file. touch -t $time_search dummy ecust_time_stamp=$(find . -name 'eCustomerCME*' -newer dummy -type f -exec ls -ltr {} \; | tail -1 | awk ' { print $6,$7,$8 } ') I calculate... (3 Replies)
Discussion started by: ragha81
3 Replies

10. UNIX for Dummies Questions & Answers

TZ out by 12 hrs

Is there a way of setting the TZ for New Zealand. I do not mind if it is only for the logged in session. It makes it hard to understand when files or CRON jobs have run when the time is set to GMT0. Any help will be appreciated. ;) (1 Reply)
Discussion started by: jagannatha
1 Replies
Login or Register to Ask a Question