Sponsored Content
Full Discussion: Alert when files change
Top Forums Shell Programming and Scripting Alert when files change Post 302956168 by dellanicholson on Sunday 27th of September 2015 10:40:33 PM
Old 09-27-2015
Alert when files change

The code I created monitors directories, files and reports when it has changed. It saves the md5sums of the files it is monitoring and sends alert whenever any files change.

It sends an excel report to admin. My code is not working. I getting error messages.

log.xlsx - the log output should look like the following:
Code:
permission      userid   group   time        size    file                      status

 
-rwxr--r--   c66770   dephrs  1:00:00:00   1435    report.java      appeared
-rwxr--r--   c74570   dephrs  2:00:00:00   6993    report2.java     changed
-rwxr--r--   c34569   dephrs  2:00:00:00   6993    report3.sas     disappeared

Here is my code:
Code:
#!/bin/bash


MONITORDIR=/opt/log.xlsx

cd /opt

NOW='date + %d%B%Y%H%M%S '

 "$MONITORDIR" > /opt/log.xlsx

   for fILE in ls -l $(find /foo/* -type f ) 
    do 
      md5sum "$(FILE)" cut -d " " -f1 > "$(MONITORDIR]"/"$(FILE)"
    done

  while :
  do

  NOW='date + %d%B%Y%H%M%S '

   for fILE in ls -l $(find /foo/* -type f ) 
     do 
  
   prev = 'cat "$(FILE)" || echo 0'
   if [-s "$(FILE); then

#it exists and has content
   md5=md5sum "$(FILE)" cut -d " " -f1 > "($MONITORDIR)"/"$(FILE)"
   
   if ["$prev" != "$md5"]; then

   case "$prev" in 
    0) echo "'date' $FILE appeared."
   *) echo "'date' $FILE changed."
   esac
  cp "$[FILE]" "$(MONITORDIR)/$(FILE).$NOW"
  
 fi
  else

# doesn't exist; did it exist before?

   if [$prev !=0]; then
   echo "date' :$FILE disappeared."
   echo > 0 "$(MONITORDIR)/$(FILE)"
   fi
 fi
 done
 sleep 10
 done

 mail -a /path/to/file/foo.xlsx -s "monitor directories and files report"         mary.email@example.com; 
jim.email@example.com


Last edited by zaxxon; 09-28-2015 at 04:46 AM.. Reason: some more code tags
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

ALERT!!! ALERT!!! I messed up the UNIX!!!

Hello If you want a short description read my last thread! I have no root access anymore. No remote access! By user access i get a programm started and when i close it, i got logged off! So I guess I messed up the passwd file! is there a chance of booting a unix system (SCO-UNIX UnixWare... (15 Replies)
Discussion started by: Fwurm
15 Replies

2. Shell Programming and Scripting

how to change mod of files

hi everyone I have a directory /usr5/sch. The shell is /bin/csh/. In this directory, I have a script called cs-claims-tst that runs an object cobol that going over a few other directory and open files and inserting them to d.b! If i run this script from its current directory, it works o.k, ... (8 Replies)
Discussion started by: naamas03
8 Replies

3. Shell Programming and Scripting

script to monitor files in a directory and sending the alert

Hi All, We are having important config files in an directory which was accessable by all /auto/config/Testbed/>ls config1.intial config2.intial config3.inital often we find that some of the lines are missing in config files, we doubt if some one is removing. I would like to write... (0 Replies)
Discussion started by: shellscripter
0 Replies

4. Shell Programming and Scripting

This script cut size of files "Lol" change string in files

Basic: find . -type f -name “*.txt” -print | awk '{gsub("Ontem", "AntesdeOntem", $0); print > FILENAME}' *.txt The idea is in folder /home/myapontamentos I have some files and i need to change in all them the word "ontem" to "antesdeontem". But bigger files are cut (size i mean)... (4 Replies)
Discussion started by: single
4 Replies

5. Shell Programming and Scripting

Find required files by pattern in xml files and the change the pattern on Linux

Hello, I need to find all *.xml files that matched by pattern on Linux. I need to have written the file name on the screen and then change the pattern in the file just was found. For instance. I can start the script with arguments for keyword and for value, i.e script.sh keyword... (1 Reply)
Discussion started by: yart
1 Replies

6. Shell Programming and Scripting

Change the content of files but not change the date

I have 100 files in a directory , all the files have a word "error" and they are created in different date . Now I would like to change the word from "error" to "warning" , and keep the date of the files ( that means do not change the file creation date after change the word ) , can advise what can... (0 Replies)
Discussion started by: ust3
0 Replies

7. Shell Programming and Scripting

Change the content of files but not change the date

I have 100 files in a directory , all the files have a word "error" and they are created in different date . Now I would like to change the word from "error" to "warning" , and keep the date of the files ( that means do not change the file creation date after change the word ) , can advise what can... (7 Replies)
Discussion started by: ust3
7 Replies

8. Shell Programming and Scripting

CLI script for emailing alert if files missing in dir

thread removed (4 Replies)
Discussion started by: billabongjimmy
4 Replies

9. Cybersecurity

**ALERT**ALERT* Whats app requesting users to upgrade to latest version as; its vulnerability found.

Hello All, Want to share here an article for Whats app users that team whats app is requesting users to upgrade to its latest version since they have found a vulnerability; where Hacker could turn on a cell's camera, mic and scan messages and emails. Here is an article from "THE VERGE" for... (1 Reply)
Discussion started by: RavinderSingh13
1 Replies
UPDATE-METAINIT(1)					User Contributed Perl Documentation					UPDATE-METAINIT(1)

NAME
update-metainit - Generates init scripts SYNOPSIS
update-metainit [--remove initname [--purge] ] DESCRIPTION
Metainit solves the problem of writing good init scripts. Instead of manually creating these important files, they are derived from a declaritive description in the metainit files in /etc/metainit. These files can be shipped with packages or created by the local adminis- trator. If update-metainit called without argument, it will regenerate init scripts for all the files in /etc/metainit. The generated files contain a large warning in form of a comment that they will be overridden. Modifications are preferably done in the files in /etc/metainit and made effective by running update-metainit. If needed, the administrator can prevent modified init files by removing the warning comment. OPTIONS
--remove initname This command will remove any generated and non-modified scripts that were created by the metainit file with the name initname. --purge Only usable with --remove. Will remove the generated files even if modified. SEE ALSO
dh_metainit(1) AUTHOR
Joachim Breitner <nomeata@debian.org> perl v5.8.8 2007-07-30 UPDATE-METAINIT(1)
All times are GMT -4. The time now is 07:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy