3

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?

1 Answer 1

1

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.

4
  • i already have execute line by line manually , i have no problem with that as well , problem start when i run the script all togother ,,,
    – moata_u
    Dec 1, 2012 at 7:48
  • lets see what shell are you using, what's the output of "ps -p $$" and whats the output of "which bash"
    – Sam
    Dec 1, 2012 at 18:00
  • both centos and ubuntu have same result : bash , /bin/bash
    – moata_u
    Dec 2, 2012 at 6:26
  • how is that you'r executing the script? you should also try to "echo" variables in different parts of your script so see where's that it's failling
    – Sam
    Dec 3, 2012 at 3:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .