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


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to find directory is getting files in every 10 mins, if not then when last time file received
# 1  
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.

Regards,
# 2  
So every 10 minutes, check the directory and if the most recent file is greater than 10 minutes old send a mail with the subject "No new files seen since ${LATEST_FILE_TIMESTAMP}"

You can use cron to run the check every 10 minutes.

and the rest could be acomplished with something like the following:
Code:
if [ $(( $(date +%s ) - $(stat -t  $(ls -lrt ${PATH_TO_RECEIVING_DIRECTORY}| tail -1 | awk '{print $NF}') | awk '{print $13}')  )) - gt 600 ]; then #
  mailx -S "No NEW FILES SEEN SINCE $(date --date=@$(stat -t  $(ls -lrt ${PATH_TO_RECEIVING_DIRECTORY}| tail -1 | awk '{print $NF}') | awk '{print $13}' )" sadique.manzar@unix.com
fi

This User Gave Thanks to Skrynesaver For This Post:
# 3  
Quote:
Originally Posted by Skrynesaver
So every 10 minutes, check the directory and if the most recent file is greater than 10 minutes old send a mail with the subject "No new files seen since ${LATEST_FILE_TIMESTAMP}"

You can use cron to run the check every 10 minutes.

and the rest could be acomplished with something like the following:
Code:
if [ $(( $(date +%s ) - $(stat -t  $(ls -lrt ${PATH_TO_RECEIVING_DIRECTORY}| tail -1 | awk '{print $NF}') | awk '{print $13}')  )) - gt 600 ]; then #
  mailx -S "No NEW FILES SEEN SINCE $(date --date=@$(stat -t  $(ls -lrt ${PATH_TO_RECEIVING_DIRECTORY}| tail -1 | awk '{print $NF}') | awk '{print $13}' )" sadique.manzar@unix.com
fi

Throws an error.line 5: unexpected EOF while looking for matching `"
# 4  
Hi Sadique,

I left out a closing parenthesis, I've also added full path to the stat command:
Code:
if [ $(( $(date +%s ) - $(stat -t  ${PATH_TO_EXISTING_DIRECTORY}/$(ls -lrt ${PATH_TO_RECEIVING_DIRECTORY}| tail -1 | awk '{print $NF}') | awk '{print $13}')  )) -gt 600 ] ; then
   echo  mailx -S "No NEW FILES SEEN SINCE $(date --date=@$(stat -t  ${PATH_TO_EXISTING_DIRECTORY}/$(ls -lrt ${PATH_TO_RECEIVING_DIRECTORY}| tail -1 | awk '{print $NF}') | awk '{print $13}' ))" sadique.manzar@unix.com
fi

# 5  
Quote:
Originally Posted by Skrynesaver
Hi Sadique,

I left out a closing parenthesis, I've also added full path to the stat command:
Code:
if [ $(( $(date +%s ) - $(stat -t  ${PATH_TO_EXISTING_DIRECTORY}/$(ls -lrt ${PATH_TO_RECEIVING_DIRECTORY}| tail -1 | awk '{print $NF}') | awk '{print $13}')  )) -gt 600 ] ; then
   echo  mailx -S "No NEW FILES SEEN SINCE $(date --date=@$(stat -t  ${PATH_TO_EXISTING_DIRECTORY}/$(ls -lrt ${PATH_TO_RECEIVING_DIRECTORY}| tail -1 | awk '{print $NF}') | awk '{print $13}' ))" sadique.manzar@unix.com
fi

Still an error:

line 3: 1534159198 - : syntax error: operand expected (error token is "- ")
# 6  
Which shell are you using?

I'm relying on a Bash convention here that anything inside $(( ...)) gets mathematically evaluated in the condidtion.
# 7  
Why not check the modified date of the directory itself? With the assumption that nothing else is going on there (any maintenance to be considered separately), it should represent the last file's arrival. Try


Code:
cd ${PATH_TO_RECEIVING_DIRECTORY}
 if (( ( $(date +%s) - $(stat -c%Y .) ) > 600 )); then echo "overdue file"; else echo "file in time"; fi
cd BACK_TO_WHERE_YOU_CAME_FROM


Last edited by RudiC; 08-14-2018 at 09:34 AM..
This User Gave Thanks to RudiC For This Post:
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #828
Difficulty: Medium
JSON and ECMAScript 2018 both allows the Unicode line terminators U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR to appear unescaped in quoted strings.
True or False?

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

Shell script to find the GB files in /tmp directory in remote server

Hi, i need help on shell scripting. Main intention of the script is step 1: ssh to remote server Step 2: cd /tmp in remote server Step 3: in tmp i want to grep only files and directories which are in GB sizes All the servers list file is - tmpsrv.txt vi tmpsrv.txt ... (17 Replies)
Discussion started by: kumar85shiv
17 Replies

3. Shell Programming and Scripting

How to select all files added to a directory in the past 5 mins (HP-UX)?

Hey everyone, I need to select all files that were added to a specific directory in the past 5 mins and copy them over to a different directory. I am using HP-UX OS which does not have support for amin, cmin, and mmin. B/c of this, I am creating a temp file and will use the find -newer command... (7 Replies)
Discussion started by: mattkoz
7 Replies

4. Shell Programming and Scripting

Shell script to find and replace contents of files in directory

Hi all This is my first post. Please bear with me with all my mistakes. I started learning shell since couple of days now and this might be quite basic for all, i want to search for files in a directory containing specific string and replace it with new string. The code i wrote is quite bulky... (2 Replies)
Discussion started by: theprogrammer
2 Replies

5. Shell Programming and Scripting

how to find first files in a directory and combine them as a single file?

i have below list of files in a directory. /root/admin/files/file1.txt /root/admin/files/file2.txt /root/admin/files/file3.txt /root/admin/files/pattern.txt /root/admin/files/server.txt i need combine the above text files in the below sequence, file1.txt, pattern.txt,server.txt =>... (8 Replies)
Discussion started by: vel4ever
8 Replies

6. Shell Programming and Scripting

Script which removes files from the first directory if there is a file in the second directory

Script must removes files from the first directory if there is a file with same name in the second directory Script passed to the two directories, it lies with them in one directory: sh script_name dir1 dir2 This is my version, but it does not work :wall: set - $2/* for i do set -... (6 Replies)
Discussion started by: SLAMUL
6 Replies

7. 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

8. UNIX for Dummies Questions & Answers

how to find the modified files before 60 mins?

hi, I need to find all the modified files before 60 minutes in a folder. Is that possible to find using mtime in minutes? Suggestions please. Thanks for looking into it... Geetha (8 Replies)
Discussion started by: iamgeethuj
8 Replies

9. Shell Programming and Scripting

shell script to find latest date and time of the files

Hi everyone, Please help:) I have a list of 1000 different files which comes daily to the directory.Some of the files are not coming to the directory now. I need to write a shell script to find the latest date and time of the files they came to the directory. The files should be unique.... (1 Reply)
Discussion started by: karthicss
1 Replies

10. Shell Programming and Scripting

Checking the time of last file received?

Hi, Is there a way of looking at the last file received and checking whether it is more than 24 hours old? E.g. /Archive/Files/h/h0012345.dat I need to look in a directory, get the date of the processed file and make sure it wasn't more than a day ago. If it is more than 1 day ago I need... (9 Replies)
Discussion started by: rebootman
9 Replies

Featured Tech Videos