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
cssd(1M)						  System Administration Commands						  cssd(1M)

NAME
cssd - daemon which invokes and watches the CSs SYNOPSIS
/usr/sbin/cssd [-f filename] AVAILABILITY
SUNWjfpu DESCRIPTION
cssd is the command which invokes and watches CS available in MLE (Multi Language Environment). After five seconds of the ending (includ- ing abnormal termination) of a CS, cssd re-invokes the CS. CS STARTING INFORMATION FILE In a CS starting information file, /etc/css.conf by default, some CS starting information directories are described. This file can be cus- tomized. cssd reads /etc/css.conf to get CS starting information directories, and then it invokes all executable files in the directories. Usually, each CS itself is not placed in the directories and is invoked indirectly from a script in one of the directories. CS STARTING SCRIPT A CS starting script is located in a CS starting information directory. cssd reads all CS starting information directories in the sequence specified in /etc/css.conf and finds to invoke all CS starting scripts. If two or more scripts which have the same filename are found, cssd invokes only the first one. UPDATING CS STARTING INFORMAION When cssd receives signal SIGHUP , it re-reads /etc/css.conf and re-finds all CS starting scripts, and then restarts, starts or terminates each script according to the following conditions. A script whose modified time is changed (is to be restarted) A script which is newly added (is to be started) A script which is deleted (is to be terminated) TO TERMINATE When cssd receives signal SIGTERM, it sends SIGTERM to each CS under the cssd's management and terminates itself (in general, each CS also terminates with the signal). ERROR INFORMATION As a facility of daemon, cssd sends error information at level `err' , and invoke/re-invoke information at level `notice' to syslogd(1M). OPTION
-f filenaSpecify a CS starting information file. Without this option, /etc/css.conf is used. FILE
/etc/css.conf file for the information of CSs by default SEE ALSO
css.conf(4), syslogd(1M) BUGS
If a CS starting script is programmed so that itself is exec-ed by a CS, cssd understands that the process of the CS starting script is terminated in spite of the CS's termination, and so puts syslog message out. SunOS 5.10 10 Jan 2003 cssd(1M)
All times are GMT -4. The time now is 04:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy