Tag Archives: email

Monitoring of changes in files at linux

I have got this script here: http://www.iamroot.ru/2013/01/kontrol-izmeneniya-fajlov-v-linux.html

Script:

#!/bin/bash

ulimit -t 20
checkdir="/bin /sbin"
filedb="/var/tmp/permsecdb"
email="test@iamroot.ru"

out=$(
exec 2>&1
umask 266
find $checkdir -type f -printf "%m\t" -exec md5sum {} \; >$filedb.tmp
diff $filedb $filedb.tmp
mv -f $filedb.tmp $filedb
)
if [ "$out" ];then 
 (date; echo; echo "$out") | mail -s "Change permsec `hostname`" $email fi

This script is checking all files in folders from “checkdir” variable, calculating their MD5 hashes, writing results to file “filedb” and compares it with results of last checking by “diff” program. If differences found then script sending email message to test@iamroot.ru. If results are identical then nothing hapens. Script needs to be launched periodically by “cron” program.