Send email if latest file in a directory is older than 2 hours


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Send email if latest file in a directory is older than 2 hours
# 1  
Old 05-16-2017
Send email if latest file in a directory is older than 2 hours

I have a objective of Sending email if latest file in a directory(excluding files of sub-dirs) is older than 2 hours.

eg :
Code:
 ls -ltr
 drwx--x--x 2 abcde abc 256 2017-02-07 20:10 Mail
-rw-rw-r-- 1 abcde abc 1170 2017-02-24 17:30 test
-rw-rw-r-- 1 abcde abc 356 2017-03-09 18:00 xyz.csv
-rw-rw-r-- 1 abcde abc 501 2017-03-09 18:05 abc2.csv
-rw-rw-r-- 1 abcde abc 415 2017-03-09 18:06 abc.csv
-rw-rw-r-- 1 abcde abc 34150 2017-03-09 18:39 test.csv
-rw-rw-r-- 1 abcde abc 119 2017-04-27 20:52 hotfix.ini



hotfix.ini is latest file in the directory, so I wish to compare the timestamp of this file with the current time of system and if file is older than 2+ hours then send mail with the time stamp of file:
hotfix.ini

It will be mostly a shell script which will run in background every 5 mins and send mail only if latest file(based on timestamp) is older than 2 hours. else would go back to sleep again for 5 mins.

Last edited by simpltyansh; 05-16-2017 at 04:26 PM..
# 2  
Old 05-16-2017
Please tell us what UNIX you are using and what shell. In this case it makes a big difference. Linux has better date/time tools than Solaris for example. So the answer to your question will be different for different OS/shell.
# 3  
Old 05-16-2017
For just the time check, try
Code:
[ "$(find . -cmin -120)" ] || echo mail -s "subject one" recipient@url.com

For the youngest file's time stamp, your attempt should work.
# 4  
Old 05-16-2017
Quote:
Originally Posted by jim mcnamara
Please tell us what UNIX you are using and what shell. In this case it makes a big difference. Linux has better date/time tools than Solaris for example. So the answer to your question will be different for different OS/shell.
Using AIX and KSH

---------- Post updated at 02:24 PM ---------- Previous update was at 08:12 AM ----------

Quote:
Originally Posted by RudiC
For just the time check, try
Code:
[ "$(find . -cmin -120)" ] || echo mail -s "subject one" recipient@url.com

For the youngest file's time stamp, your attempt should work.
Hi Rudi,

Can you help me with the complete script, I didn't get your solution.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Send an email if "No such file or directory" in the shell script program log in EBS concur

Hi All, I have the below code(.sh) and need to send an email. #!/bin/bash cp /u02/xxc_incoming/TEST*.dat /u02/xxc_archive_incoming/AMER7764_ARPP_2/ cat /u02/xxc_incoming/TEST*.dat > /u02/xxc_incoming/XXC_TEST.dat rm /u02/xxc_incoming/TEST*.dat cd $XXC_TOP/bin sqlldr userid=apps/<pwd> ... (12 Replies)
Discussion started by: Mist123
12 Replies

2. Shell Programming and Scripting

To get older than last 7days records using awk scripting to generate report and send email

Hello All, I have need as below: 1--> I need to get all users(who submit jobs) and their details by using below command: qstat -u \* output of the above command looks line below: job-ID prior name user-id state "submit/start at" queue jclass slots ja-task-ID... (5 Replies)
Discussion started by: VasuKukkapalli
5 Replies

3. Shell Programming and Scripting

Loop multiple directory, find a file and send email

Hello ALL, need a BASH script who find file and send email with attachment. I have 50 folders without sub directories in each generated files of different sizes but with a similar name Rp01.txt Rp02.txt Rp03.txt ...etc. Each directors bound by mail group, I need a script that goes as... (1 Reply)
Discussion started by: penchev
1 Replies

4. Shell Programming and Scripting

files older than few hours

Hi All I need to know the command which can be used to list the files which are 3 hours old so that it can be deleted. (3 Replies)
Discussion started by: mskalyani9
3 Replies

5. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

6. Shell Programming and Scripting

Shell script: If a file stays in a particular directory more than 30 min send an email

Hi , I am new to shell scripting. i have a requirement say i will receive a file in a directory say /xyz.if that file stays in that directory more than 30 min i need to get a mail to my outlook.this should run for every 20 min in crontab. can anyone help me? (8 Replies)
Discussion started by: muraliinfy04
8 Replies

7. Shell Programming and Scripting

Move the latest or older File from one directory to another Directory

I Need help for one requirement, I want to move the latest/Older file in the folder to another file. File have the datetimestamp in postfix. Example: Source Directory : \a destination Directory : \a\b File1 : xy_MMDDYYYYHHMM.txt (xy_032120101456.txt) File2: xy_MMDDYYYYHHMM.txt... (1 Reply)
Discussion started by: pp_ayyanar
1 Replies

8. Shell Programming and Scripting

shell script to send email with usage of space in the directory as description :

shell script to send email with usage of space in the directory as description : Please any one help me in writing a script to send email with usage of space in the directory as description . (3 Replies)
Discussion started by: sakthifire
3 Replies

9. AIX

how to find files older than 2 hours

I need help to find files in a directory that are older than 2 hours. Any help would be great. (3 Replies)
Discussion started by: pt14
3 Replies

10. Shell Programming and Scripting

unix command/s to find files older than 2 hours in a directory

I need to write a script to find files older than 2 hours in set of direcotries and list them ina mail. I know find command ti list files greater/lesser than days but i need to do it for hours. Any input. (6 Replies)
Discussion started by: Presanna
6 Replies
Login or Register to Ask a Question