Monitor File Changes | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Monitor File Changes

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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.

Thanks,
Goreb
Sponsored Links
    #2  
Old 07-10-2005
vino's Avatar
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 9 April 2013, 8:19 AM EDT
Location: Sydney, Down Under
Posts: 2,847
Thanks: 0
Thanked 12 Times in 12 Posts
Here's something for you...


Code:
#! /bin/sh

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

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

# 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
touch -r $MONITORED_LOG $TEMP_LOG

Vino
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 12:14 AM.