File Modified : Alert me


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers File Modified : Alert me
# 1  
Old 03-10-2007
File Modified : Alert me

I would like to alert myself when a file has been modified using a script but im not sure where to begin the only command i can think to use is the touch command
# 2  
Old 03-10-2007
You can do something like below: This is just considering the same time..You may need to modify it if you want to consider same time for different day..
Code:
time=$(ls -l $1 | awk -F" "  '{ print $7 }')
while :
do
   chk_time=$(ls -l $1 | awk -F" "  '{ print $7 }')
   if [ "$chk_time" != "$time" ]
   then
      echo "File modified"
      mailx -s "File $1 modified"  abc.dfg@xxx.com
      break; # if you want to stop the script once mail is send
   fi
   sleep 5  # 5sec wait time
done


Last edited by Yogesh Sawant; 06-01-2010 at 10:28 AM.. Reason: added code tags
# 3  
Old 03-11-2007
thanks a lot for the script but what if I'm offline and someone else modifies the script..how would i get an alert then?
thanks a million
# 4  
Old 03-11-2007
What form would you envisage the alert taking in that case?
# 5  
Old 03-11-2007
Quote:
Originally Posted by reborg
What form would you envisage the alert taking in that case?
if i were offline i'd expect to be notified through email..I guess i'd want to monitor the file even when im offline if that's possible?
perhaps i could schedule an at job to run the script every so often?
# 6  
Old 03-12-2007
Hi,

One option which is coming to my mind is to make use of the "nohup" for this script.

Thnx.
Dennis
# 7  
Old 04-08-2008
This works for me..

I have this running in a cron job every hour.. it creates a dummy-file for the time-stamp, but it's pretty nice otherwise, if I do say so myself :^)

Code:
#!/bin/bash

USAGE="$0 <full-path-of-filename> <email-addresses..>"

if ! [ -e $1 ]; then
   echo $USAGE
   exit 1
fi

file=$1
dir=$(dirname $1)
timestampFile=$1-watching
shift
emails=$@

# if the timestamp file does not yet exist, create it
if ! [ -e $timestampFile ]; then
   touch -r $file $timestampFile
   echo " You will be notified within the hour that $file is modified " | mailx -s "kiowa feed watch: $(basename $file)" $emails
   exit 0
fi

timestamp=$(date -r $timestampFile)
nowstamp=$(date -r $file)
if [[ "$timestamp" == "$nowstamp" ]]; then
   exit 0
else
   echo "$file changed timestamps from  $timestamp  to  $nowstamp"| mailx -s "kiowa feed watch: $(basename $file) *** ALERT ***" $emails
   touch -r $file $timestampFile
fi

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Who has modified a file - History?

Hello, I'd want to know who and what time has modified a file in unix (history). I'd like to know all people who has modified a file. Thanks in advance (6 Replies)
Discussion started by: nurinolo
6 Replies

2. Shell Programming and Scripting

shell script to alert if a file has been modified

Hi , I want a script who will send alert the moment someone edit any file in a directory in LINUX. Can some one throw some light on this please.!! (4 Replies)
Discussion started by: d8011
4 Replies

3. Shell Programming and Scripting

Script to check for the file existence, if file exists it should echo the no of modified days

Hi, I am looking for a shell script with the following. 1. It should check whether a particular file exists in a location #!/bin/sh if ; then echo "xxx.txt File Exists" else echo "File Not Found" fi 2. If file exists, it should check for the modified date and run a command... (2 Replies)
Discussion started by: karthikeyan_mac
2 Replies

4. Shell Programming and Scripting

changing a file when the inode modified time of the other file changes

i have a requirement where i needed to change variable values in a properties file(first file) whenever there is change to Release details file(second file). My question is do i have to create a daemon process that always checks the modified time/inode change of the second file and then change the... (1 Reply)
Discussion started by: saikiran_1984
1 Replies

5. Shell Programming and Scripting

How long since file has been modified

how can I find out if a file has been modified less than 24hrs ago (3 Replies)
Discussion started by: BeefStu
3 Replies

6. Shell Programming and Scripting

How to get a filename modified by attaching modified timestamp

Hi, I want to modify a filename in AIX by attaching the last modified timestamp. I want the timestamp completely in numerical format (eg:200905081210. yr-2009, mnth - 05, date -08, hr - 12, mins - 10). For example if the filename is a.log and it was modified on April 6th 2008 at 21.00. I... (16 Replies)
Discussion started by: Ruks
16 Replies

7. Shell Programming and Scripting

How many days since a file was modified?

I am trying to write a script to backup my laptop to a NAS drive using rsync. I want the backup to be done, only if it has been more than a week since my last backup. Each time the rsync command executes, I also create a file backuptime.txt file, with the time at which the script completed the... (1 Reply)
Discussion started by: anandjayaraman
1 Replies

8. UNIX for Dummies Questions & Answers

how to retrieve original contents of a modified file (modified using vi)

Made changes to a file using vi editor and saved those changes now realised that the changes are not required How can I get the previous version of the file.i.e the one which was there on which I had made changes (3 Replies)
Discussion started by: novice100
3 Replies

9. UNIX for Dummies Questions & Answers

who modified my file!!

Hi EVERYONE!!... Just a simple (yet critical from my perspective) doubt... I would like to know who had edited my file.. when I use ls -l command, I see my ID.. but when I edit using some other ID, I had expected that ID to be shown.. but still ls -l shows my ID only.. So, is there any... (4 Replies)
Discussion started by: mohanprabu
4 Replies

10. Programming

File last modified

I cannot read the last moment the file was modified - it returns "Most recent access" instead: code: </td> <th><?FILE *fatr=fopen(iindname.c_str(), "r"); if(fatr){ struct stat statbuf; fstat(fileno(fatr), &statbuf); fclose(fatr); ?> ... (4 Replies)
Discussion started by: szzz
4 Replies
Login or Register to Ask a Question