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?
# 8  
Old 07-22-2014
OS is SunOS 5.10 Generic_144488-04 sun4u sparc SUNW,Sun-Fire-V490

This is what I have tried so far ..

Code:
for i in $(find /path/to/search -type f -mmin -10)
do
  if [[ -s "${i}" ]]; then
    grep "xyz" "${i}" >> xyzfound
  fi
done

and I got the following error

Code:
/usr/bin/find: bad option -mmin
/usr/bin/find: [-H | -L] path-list predicate-list


Last edited by rbatte1; 07-22-2014 at 09:19 AM.. Reason: Code tags
# 9  
Old 07-22-2014
I asked:-
  • What logical process have you considered?
Do you have any thoughts on this? If the flags you have for find are not supported on you server, we'd have to think our way round it and we could go down several routes, I'm sure. If you can suggest your logic, then we can suggests processes to achieve them.



Robin
# 10  
Old 07-22-2014
the logical process I have considered is the suggestion from RudiC
I am going to perform the checks in myfirst script but the only catch here is I cannot modify my first script heavily ...

my first script knows it has written the file and saves it in a variable
Code:
$directory/$myFile

I need to now kick of another script from the original script that would take the $myFile as input and do all the checks

So any suggestions on how do i call a new script from my first script that takes
Code:
$directory/$myFile

as input and perform the checks in my new script
# 11  
Old 07-22-2014
Quote:
my first script knows it has written the file and saves it in a variable
Code:
$directory/$myFile

This isn't really a variable, it looks more like a file.

Are you wanting you scheduled script to just call another script as it ends? Simply put it in (before you exit) and it will get brought along. You may need to give it the full path. If you have the values you need as variables, you can do something like this:-
Code:
/path/to/mynewscript $var1 $var2 $var3

It should fire up your new script and that will be able to use something like this:-
Code:
my_var1="$1"
my_var2="$2"
my_var3="$3"

Have I missed the point?

If you are storing lots of values in the file $directory/$myFile then it depends how they are stored as to how we read them back in to your called script.



Robin
# 12  
Old 07-22-2014
Would incron (cron-like utility for file system events rather than time) do what you are trying to do much better?

I monitor particular files or folders for a file write-close event and then kick of scripts with incron. I handle web input (radio button state and password) in bash (because I don't know much CGI) to reboot my home server, turn on or off VNC or FTP, share media directories for a fixed timeout period, etc. Also any time someone uploads a file by anonymous FTP, incron detects it and I whisk it away to a private folder for review/inspection. This allows individual FTP users to submit files that other FTP users cannot access or even see the file name.

You could just have incron call the second script when the first script finishes it's output.

Check it out: Incron

Mike
# 13  
Old 07-22-2014
Solaris does not have inotify so incron may not be useful. Solaris does not come with GNU date. You have to work harder on it. Here is a straight Solaris example using perl, and the touch and find commands.

Code:
# touch -t [[CC]YY]MMDDhhmm[.SS] filename
# sets file time on a file

# find the time -10 minutes ago:
minus10()
{
 perl -e '  
 $now=time;
 $now-=600;   # ten minutes ago
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($now);
 printf  "%d%02d%02d%02d%02d.%02d",
         $year+1900, $mon+1, $mday, $hour, $min, $sec;'
}         

########################### demo section to understand code
 touch dummy
 echo 'file time for now ='
 ls -l dummy
 # change the file time on the file
 touch -t $(minus10)   dummy
 echo 'file time 10 minutes in the past ='
 ls -l dummy
############################  end demo remove after you play with it.
 
#########  Use this part plus minus10 function to find recent files
touch -t $(minus10) /tmp/dummy

find /path/to/files -type f  -newer /tmp/dummy |
  while read fname
  do
    # work with the file like ls -l $fname
    # echo $fname is new >> some.logfile
  done

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