#!/bin/sh
find . -name "common.log.diff" > /dev/null 2>&1
if [ $? -eq 1 ]; then
cp common.log common.log.diff
diff common.log common.log.diff > DIFFERENCE.log
cp common.log common.log.diff
grep "ERROR" DIFFERENCE.log
if [ $? -eq 0 ]; then
echo "1" > sitescope.log
else
echo "0" > sitescope.log
fi
else
diff common.log common.log.diff > DIFFERENCE.log
cp common.log common.log.diff
grep "ERROR" DIFFERENCE.log
if [ $? -eq 0 ]; then
echo "1" > sitescope.log
else
echo "0" > sitescope.log
fi
fi
And also I have made an entry in crontab as follow for the auto execution of script.
45,46,47,48,49,50,51,52,53,54,55,56,57,58,59 * * * * /tmp/test/ts.sh
This will execute the script for every mentioned minute of an Hour. (45,46----59)
I have copied following files and script under /tmp/test/
[/tmp/test]: ls -lrt
total 16
-rwxr-xr-x 1 89 Nov 28 00:40 common.log
-rwxr-xr-x 1 508 Nov 28 00:52 ts.sh
As per the script when it run's at first attempt, it will create a file named as common.log.diff.
And it does worked, but only for manual execution. When put in crontab it is not working.
There are a couple of points to get you moving.
1) The "." in the find statement is relative to the home directory of the account for that crontab user (which is probably not /tmp/test).
On the line before the find, first try changing to the directory from which the script was called.
cd "`dirname $0`"
2) Any output from a cron job goes to the mail account for that crontab user. That's where to look for the reason for a cron failing.
3) There are tidier ways of finding out whether a file has gained one of more lines containg the text "ERROR". Because "diff" shows the context around the difference you may get false matches. Unless you use "grep -q" or redirect the output the results will appear in the mail for that crontab user.
4) Did you use "crontab -e" to edit the crontab ? If not, cron won't know that the file has changed.