LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-30-2012, 10:29 AM   #1
epomqo
LQ Newbie
 
Registered: Jan 2012
Posts: 1

Rep: Reputation: Disabled
bash script for monitoring file update


Dear all,

I wish to monitor the change of a file in the UNIX system to see if it has been updated consistently. What I had in mind is to return the last modification date of the file, and compare it with the current time in the system (output of command "date"). If the difference is bigger then three minutes, then the file has not been updated in the last three minutes and I wish the system to send me an alert email.

I am not sure if this is feasible with BASH command in the UNIX system. If yes, can anyone give me some hints on how to achieve this?

Many thanks in advance,
epomqo
 
Old 01-30-2012, 11:01 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
If you use Inotify (inotifywatch or incron) instead you only have to watch for the event you are really interested in (say write) and use a countdown timer?
 
Old 01-30-2012, 02:11 PM   #3
JHO5
LQ Newbie
 
Registered: Jan 2012
Distribution: RHEL5/6
Posts: 6

Rep: Reputation: Disabled
You could setup a small script that basically does a:
Code:
 stat -c '%y' <filename>
That will provide you with the last modification time/date. Anyway, set that up as a cron job to run every 3 minutes if you want and put some sort of if condition where if the time is more than 3 minutes out of sync, you could have it notify you however you want.
 
Old 01-30-2012, 02:16 PM   #4
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by unSpawn View Post
If you use Inotify (inotifywatch or incron) instead you only have to watch for the event you are really interested in (say write) and use a countdown timer?
this is really good stuff - incrond / inotify

sending email notify on change in directory/file

Last edited by lithos; 01-30-2012 at 02:21 PM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Update csv file into mysql db via bash script xmrkite Linux - Software 4 01-13-2010 12:43 AM
Port Monitoring bash script twantrd Programming 15 01-29-2009 12:59 AM
Bash script for monitoring changes in a directory tree librano Linux - Software 4 10-30-2008 07:36 PM
Sed doesn't update file in bash script chilebiker Programming 4 06-14-2007 08:25 AM
bash script, monitoring running PID? thebover Programming 4 08-26-2004 02:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration