Unix/Linux Go Back    

Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Monitor File Changes

Shell Programming and Scripting

Closed Linux or Unix Question    
Thread Tools Search this Thread Display Modes
Old Unix and Linux 07-07-2005
goreb13 goreb13 is offline
Registered User
Join Date: Jul 2005
Last Activity: 7 July 2005, 4:14 PM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Monitor File Changes

I am trying to monitor a log file and kick of a script when a change occurs. I know I could do this with a cron job and check for differences at set intervals, but I need the script to be dynamic and notify me as soon as there is a change in the log file. If anyone knows of a way to do this please help.

Sponsored Links
Old Unix and Linux 07-10-2005
vino's Unix or Linux Image
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
Join Date: Feb 2005
Last Activity: 12 March 2015, 5:33 AM EDT
Location: Sydney, Down Under
Posts: 2,848
Thanks: 0
Thanked 13 Times in 13 Posts
Here's something for you...

#! /bin/sh

# This is the log that will be monitored. 
# If any changes occur to this, then take appropriate action.

# We will need this log to see whether any changes occured to /tmp/goreb.log

# This is a 1-time command i.e. create the log file if it does nto exist.
[ ! -f $TEMP_LOG ] && touch -r $MONITORED_LOG $TEMP_LOG

[ $MONITORED_LOG -nt $TEMP_LOG ] && echo "$MONITORED_LOG is newer than $TEMP_LOG. Carry out your required operations"

# Update $TEMP_LOG with the new modified date of $MONITORED_LOG

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Monitor log file dholmaster Shell Programming and Scripting 5 05-13-2012 07:39 PM
Continiously monitor the log file arumon Shell Programming and Scripting 4 10-27-2011 07:50 PM
Help to Monitor the existence of a file dinesh1985 Shell Programming and Scripting 1 11-16-2009 06:20 AM
Monitor on file suresh_krish Shell Programming and Scripting 1 04-21-2009 05:39 AM

All times are GMT -4. The time now is 10:30 PM.