I am trying write a script to find all changes (modify,create,delete) in a list of directories for last 24h, as the following :
#!/bin/bash
LOGDIR=change_log
FILETYPE=*.php
DIR=www
OUTPUT=$LOGDIR/$(date +%Y-%m-%d).log
function start_check {
for i in `find . -name $DIR -type d`;do
used=0
for j in `find $i -name "${FILETYPE}"`;do
case `find $j -mtime -1` in
'');;
*)
if [ "$used" = "0" ];then
current_directory=`echo $i | cut -d'/' -f2`
display "$current_directory"
fi
echo $j >> $OUTPUT
used=1
;;
esac
done
done
}
function display {
echo "---------------------------------------" >> $OUTPUT;
echo "$@" >> $OUTPUT;
echo "---------------------------------------" >> $OUTPUT;
}
MAIN(){
echo "START CHECKING" > $OUTPUT
start_check;
}
MAIN
Problem is , when I run the script in Ubuntu, I can't find any problem , but when I run the script in centos, it can't find any changes, the result is NULL .
Any idea?
well, its a bash script, so i'd recommend you to debug the program by executing line by line by copying line by line into a terminal and see where it is that it fails,
for example, one potential cause of the problem is that in centos, for some reason it's not finding any files/folders, so manually execute the
find . -name "www" -type d
instruction and see if it returns an expected result.Repeat that process for every instruction in your program, it shouldn't take long since its a small program.