Find file that are accessed less than 10 minutes in a directory


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Find file that are accessed less than 10 minutes in a directory
# 1  
Old 11-15-2018
Find file that are accessed less than 10 minutes in a directory

Hi All,,

I need to find the latest files that are accessed less than 10mins in a particular directory & send those files in an attachment.

I could use the below simple one. But if the directory was not updated any recently i could mail the old file again, i need to eliminate that.. What shld i do for this.

Code:
newest=$(ls -lrt | tail -n 1)
uuencode (PATH) "$newest" | mailx -s "Subject" "name@domain.com"

Appreciate your help!

Thanks




Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by Jeevitha; 11-15-2018 at 07:12 AM..
# 2  
Old 11-15-2018
Well specifying the operating system and shell would be a start.

Check out find and atime (access time) option.
The filesystem mounted will need to have atime attribute on (most have by default), other don't due to possible performance reasons.


Hope that helps.
Regards
Peasant.
# 3  
Old 11-15-2018
Its HP-UX & bash shell

yeah, i checked with find & atime option. Its giving the files that are accessed in 'days' i.e atime -1 gives the files accessed less than in a day

But i need to check the files accessed in 10 mins time.

Any leads?
# 4  
Old 11-15-2018
Well HPUX find does not support minutes with atime.
There is not stat either.

So either perl(stat) or C (fstat) to manipulate (older then) comes to mind.
I'll have to look into it to produce some code on HPUX box, have to get back to you tomorrow or next week.


Regards
Peasant.
# 5  
Old 11-15-2018
How about newer option of find?
Is that available?
# 6  
Old 11-15-2018
As far as i get it, if you operate within same directory, the operation of 'sending those files' will change the atime again.
So next iteration of code will detected those again as accessed in the last 10 minutes (10 minutes or less).

This could be mitigated by issuing touch -at <TIMESTAMP> files to change all files sent 20 minutes behind script execution time.
This will, of course, fake atime on processed files.

As for -newer i'm not sure it will operate on atime or ?

Perhaps some awk parsing and ls -lutr... shouldn't be to big.
I'll get back to you on that when i get to hpux box these days Smilie

Regards
Peasant
# 7  
Old 11-19-2018
Hi,

I have written a code with the below concept. Does it make sense?

Step 1:getting the newest file from ls -lrt | tail -1 & sending the file as an email attachment ( This is my req. need to find the recently accessed file & send it as attachment in an email)
Step 2: Move that file in to a back up directory. So that same file will not get accessed in the next run
Repeating this step via script managed by a scheduler.

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find if create time of last created file in a directory is older than 5 minutes

A process xyz is running and creating file1, file2, file3, .... filen. how do i know if the process has stopped and createtime of the last file (filen) is older than 5 minutes? OS is AIX (3 Replies)
Discussion started by: malaika
3 Replies

2. Shell Programming and Scripting

Check file creation Time minutes and if file older then 5 minutes execute some stuff

Hello all, Info: System RedHat 7.5 I need to create a script that based on the creation time, if the file is older then 5 minutes then execute some stuff, if not exit. I thought to get the creation time and minutes like this. CreationTime=$(stat -c %y /tmp/test.log | awk -F" " '{ print... (3 Replies)
Discussion started by: charli1
3 Replies

3. Shell Programming and Scripting

Grep a log file for the last 5 minutes of contents every 5 minutes

Hi all, System Ubuntu 16.04.3 LTS i have the following log INFO 2019-02-07 15:13:31,099 module.py:700] default: "POST /join/8550614e-3e94-4fa5-9ab2-135eefa69c1b HTTP/1.0" 500 2042 INFO 2019-02-07 15:13:31,569 module.py:700] default: "POST /join/6cb9c452-dcb1-45f3-bcca-e33f5d450105... (15 Replies)
Discussion started by: charli1
15 Replies

4. UNIX for Beginners Questions & Answers

How to find and get a file in an entire directory with an excluded directory specified?

How to get a file 'zlib.h' in an entire directory with an excluded directory specified lives under that starting directory by using find command, as it failed on: $ find . -name 'zlib.h' -a -ipath 'CHROME.TMP' -prune -o -print it'll just list entirely up (2 Replies)
Discussion started by: abdulbadii
2 Replies

5. UNIX for Advanced & Expert Users

How to find out last 5 users who have accessed a file?

Hi All, is there any command or script to find out last five users who have accessed a file thanks jcpratap (1 Reply)
Discussion started by: Jcpratap
1 Replies

6. Shell Programming and Scripting

Find out whether directory has been updated with files in the last 5 minutes or not

Hi, I am trying to work on this script that needs to monitor a Directory. In case there are no files received in that Directory for the last 5 minutes, it has to send out an alert. Could someone please suggest any approach for the same. Note: I did check out various previous psts -... (8 Replies)
Discussion started by: rituparna_gupta
8 Replies

7. Shell Programming and Scripting

Log to find users who accessed server before

Hi, please provide the steps/commands to find out the user id list who accessed server before i logon same server. Thank you very much ffor all your support. (2 Replies)
Discussion started by: sridhardwh
2 Replies

8. Shell Programming and Scripting

Find the age of a file in Minutes

KSH: Please lt me know how to find the age of a file in minutes(Based on last modified time). ie, if the file was modified 15 Minutes ago, the output should be 15 (1 Reply)
Discussion started by: hari_anj
1 Replies

9. UNIX for Advanced & Expert Users

Find accessed file in past 1 or 2 minutes, and throw mail.

Can Anyone tell me how to write the Script to "find file(s) in a directory that is being accessed in last 5 minutes, and if there is result of that find, then throw the mail ". Means throw the mail to a person regarding whoever and whenever a file is accessed in a directory. ASAP. Thnks. (2 Replies)
Discussion started by: varungupta
2 Replies

10. Shell Programming and Scripting

Find files not accessed on a remote server and delete - Help!

Hi Guys, I am currently working on a script to find all the files that have not been accessed for the past 2 years. This, i guess has been discussed n number of times in this forum. Now, my requirement is to find all the files in the remote windows server. I have it mounted in unix. I was... (1 Reply)
Discussion started by: bond_bhai
1 Replies
Login or Register to Ask a Question