Script not executing in CRONTAB

Hi,

I have written a script for file scan :

#!/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.

Kindly advice me on this.

Regards

Please use the search forum for cron or crontab issues - this kind of question is asked very often. There is also a good guide here:

Instead of using blue letters you can also use the code tags to also presave spaces etc. when posting code or logs etc.

how do we check the crontab environment ?

It would be nice if you read the article I linked 1st. There is a paragraph with a bold header called:

Hi ,

I have gone through the tutorial and checked the environment difference . The crontab is running in ksh . So, I also changed my script to #!/bin/ksh.

But it did not work . May be I wrong somewhere else. Kindly advice.

Regards

Write the stdout and stderr to some file and post it here.

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.

First let's get the cron to run.