#!/bin/sh searchdir=/root log=/tmp/filescan tmp=/tmp/filescan.tmp i=0 for arg in $* ; do if test $i -eq 1 then searchdir=$arg break fi if test "$arg" = "-d" then i=1 fi done if test -e $tmp then echo "The script is already running" exit 1 elif ! test -e $searchdir || ! test -d $searchdir then echo "No directory given for scanning or directory path is wrong ($searchdir)" exit 1 fi if test "$1" = "initial" then touch $log find $searchdir -type f -exec md5sum '{}' > $log \; elif test "$1" = "scan" then if test -e $log then find $searchdir -type f -exec md5sum '{}' > $tmp \; oldsum=$(md5sum $log | awk -F "\s" '{print $1}') newsum=$(md5sum $tmp | awk -F "\s" '{print $1}') if test "$oldsum" = "$newsum" then echo "No changes in searchdir $searchdir" else echo "New or changed files in $searchdir" echo "old $oldsum" echo "new $newsum" fi rm $tmp else echo "File with hashes not found. You might want to run with initial parameter to create this file" exit 1 fi else echo "Usage : scandir initial|scan [-d /path/to/scan]" echo " First argument must be either initial or scan." echo " -d is not mandatory" echo "initial : the script scans the \$searchdir and creates hashes of files" echo "scan : the script scans \$searchdir for changed/new files" echo "-d : specifies the \$searchdir as argument." echo " If not given the default value $searchdir is used" fi exit 0