How to check if there is a file in the last 10 mins?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check if there is a file in the last 10 mins?
# 1  
Old 07-22-2014
How to check if there is a file in the last 10 mins?

I have a script that runs every hour from the crontab (see the settings of the crontab below) (15 mins past the hour)

Code:
15 * * * * /home/usr/usr1/ProvAll

This script saves two files in the following format

Code:
now=`/bin/date '+%Y%m%d.%H%M%S'`

file1.$now (for example)
file1.20140722.031502
file2.20140722.031502

I would need help in writing another script and kick of using the following crontab settings (20 mins past the hour)

Code:
20 * * * * /home/usr/usr1/mynewscript

the purpose of this "mynewscript" is to

1) to check if there are any files with the above format written in the directory in the last 10 mins

file1.20140722.031502
file2.20140722.031502

2) if the files are there then check the size of those files, if the file size of the files are zero then exit else

3) grep for a word 'xyz' from those file and save the output into a new file (xyzfound) if that word is found

Last edited by Scrutinizer; 07-22-2014 at 02:57 AM.. Reason: CODE tags
# 2  
Old 07-22-2014
If the directory is /path/to/search
Code:
 
for i in $(find /path/to/search -type f -mmin -10)
do
  if [[ -s "${i}" ]]; then
    grep "xyz" "${i}" >> xyzfound
  fi
done

# 3  
Old 07-22-2014
find: bad option -mmin
find: [-H | -L] path-list predicate-list
# 4  
Old 07-22-2014
What's your OS?
# 5  
Old 07-22-2014
Sun Solaris 10
# 6  
Old 07-22-2014
Why don't you perform the checks in your first script? It should know if it has written the files, size can be immediately checked, as well as the xyz contents...
# 7  
Old 07-22-2014
Hello knijjar,
I have a few to questions pose in response first:-
  • What have you tried so far?
  • What OS and version are you using? It may tell us what tools you have. - Oh, okay you answered this before I pressed the submit button! Smilie
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.

It seems like you might need a trick to work out the time 10 minutes ago, create a reference file with the correct time stamp and then use the -newer flag of find.


Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to find directory is getting files in every 10 mins, if not then when last time file received

Dears, I am looking for a script which will work as a watch directory. I ha directory which keep getting files in every 10 mins and some time delay. I want to monitor if the directory getting the files in every 10 mins if not captured the last received file time and calculate the delay. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

2. Shell Programming and Scripting

Need logs 5 mins old

I need 5 mins old logs to be dumped into a a new file. The date formats in the two log files are Can you suggect for both formats ? bash-3.2$ uname -a SunOS myserver 5.10 Generic_150400-26 sun4v sparc sun4v ---------- Post updated 05-04-16 at 12:24 AM ---------- Previous update was... (2 Replies)
Discussion started by: mohtashims
2 Replies

3. UNIX for Dummies Questions & Answers

Script to search log file for last 15 mins data

Hi All, I have an issue which I'm trying to understand a way of doing, I have several nodes which contain syslog events which I want to force trigger an email initially (eventually leading to another method of alerting but to start with an email). Basically the syslog file will have hours worth... (6 Replies)
Discussion started by: mutley2202
6 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Check for a file and keep waiting for 30 mins

Hi All! I want to have a shell script that checks for a file in a particular folder and then if the file is not found it should wait for 30 minutes. Again check for the file, if it FOUND then successfuly exit the shell script stating the file is found. Else it should continue to wait. ... (4 Replies)
Discussion started by: akshay01987
4 Replies

5. AIX

Grep last 5 mins from log file in AIX

I want to grep only last 5 mins of a log file in bash I have a syslog which contains the following Mon Jul 11 20:47:42 Mon Jul 11 20:47:52 The following works in Unix but not in AIX . Please can you let me know as to what would be the AIX equivalent Code: for (( i = 5; i >=0;... (1 Reply)
Discussion started by: necro98
1 Replies

6. Shell Programming and Scripting

Retrieve logs generated in last 10 mins from a log file using 'grep' command

HI All, I have a log file where the logs will be in the format as given below: 2011-05-25 02:32:51 INFO PROCESS STARTING 2011-05-25 02:32:52 INFO PROCESS STARTED . . . I want to retrieve only the logs which are less than 5 mins older than current time using grep... (3 Replies)
Discussion started by: rvhg16
3 Replies

7. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

8. Shell Programming and Scripting

file old than 10 mins to alert

Hello We have to monitor a FTP utility where we have to monitor for checking presence of a file in directory With max time allowed for a file to stay in the directory on FTP client server as 10 mins. The only way we are going to be able to do what we are lookign for is to write a script to... (1 Reply)
Discussion started by: vivkas
1 Replies

9. Shell Programming and Scripting

Script which will search for a file for 15 mins

Hi All, I would like to write a script which will search a file say abc.dat in /a/b/data for 15 mins only. If the script finds the file in 15 mins then it will exit will exit sucessfully and if there is no file for 15 mins it will exit and copy the last day file (abc.dat_ddmmyyhhmmss) from... (1 Reply)
Discussion started by: chandancsc
1 Replies

10. UNIX for Dummies Questions & Answers

Script to check for a file, check for 2hrs. then quit

I wish to seach a Dir for a specific file, once the file is found i will perform additional logic. If the file is not found within two hours, i would like to exit. Logically, I'm looking for the best way to approach this Thanks for any assistance in advance. Note: I'm using a C shell and... (2 Replies)
Discussion started by: mmarsh
2 Replies
Login or Register to Ask a Question