Cron job is not working in the desired manner on IBM AIX

Hi,
I have created a cron job on IBM AIX but it is not working in desired manner !
Here are the steps which I have followed :-

#!/bin/ksh
#------------------------------------------------------------------

find /some/file/at/the/user/side/test.log -exec cp {} /other/file/at/the/user/side/testBackup.log \;

cat /dev/null > test.log

tar -cvf test testBackup1.log.tar /other/file/at/the/user/side/testBackup.log

gzip /other/file/at/the/user/side/testBackup1.log.tar

chmod +x CronScript.ksh


echo "\n****************************************************\n"
echo "Done"
echo "DATE: ${DATE}"
echo "\n****************************************************"

Purpose of this Script :- (a.)The above script will copy the contents of parent file into the child file at some location.

                                             \(b.\) After copying the contents from the parent file, the script will make the parent file empty.

                                             \(c.\) Then it will tar and gzip the child file.

(2.) After this I created a cron file net-sense.cron

In this I wrote the following things :-

5 15 19 6 2 /some/file/at/the/user/side/CronScript.ksh

Purpose of this :- This cron job was supposed to run at 15:05 hrs 19th June Tuesday and should have performed the steps in the CronScript.ksh

                               The cron job ran at the above mentioned time but it failed to :-

(a.) Empty the parent file
(b.) Tar and gzip the child file

When I execute the CronScript.ksh separately I am getting the desired output but I do the same with the help of cron I am getting the desired output ! L

Can anyone please let me know that where I have failed in the logic implementation !

Please help me out in getting the desired output with the help of this cron job !

check the mail for cron messages and what it says ?

could you please let me know where to check for the mail on IBM AIX ? As I am totally new to it !

Seem to me quite normal...
Where were you (dir...) when you executed the script?
Where do you think cron is?
You nulled test.log in current directory, but did you define the current directory in your cron file?
Same goes for tar...

Lesson:
In a cronfile, you need to define All the environment (and the others ...) variables you are to use.

cron is very dumb and has a very limited PATH set
cron does not like things related to tty ( TERM set keyboard defs etc...)

check the last mails for the actual time that you executed the cron job

# mail
& h $

and then for example the output

U3180 root@XXXXX  Wed Jun 20 07:01  26/1073  "Cron <root@XXXXX> run-parts /etc/cron.hourly"
U3181 root@XXXXX  Wed Jun 20 08:01  26/1073  "Cron <root@XXXXX> run-parts /etc/cron.hourly"
U3182 root@XXXXX  Wed Jun 20 09:01  26/1073  "Cron <root@XXXXX> run-parts /etc/cron.hourly"
U3183 root@XXXXX  Wed Jun 2

chek the last mails to header number and look at the below lines

& 3183

Message 3183:
From root@XXXXX  Wed Jun 20 10:01:01 2012
Date: Wed, 20 Jun 2012 10:01:01 +0300
From: root@XXXXX (Cron Daemon)
To: root@XXXXX
Subject: Cron <root@XXXXX> run-parts /etc/cron.hourly
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/usr/bin/ksh>
X-Cron-Env: <PATH=/sbin:/bin:/usr/sbin:/usr/bin>
X-Cron-Env: <MAILTO=root>
X-Cron-Env: <HOME=/>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>

execl: couldn't exec `/usr/bin/ksh'     ###  --> Any message like these ?
execl: No such file or directory                      ###

i checked at the location /usr/spool/mail and got the following message :-

 
From daemon Tue Jun 19 15:06:01 2012
Received: (from daemon@localhost) by bluestar (AIX5.3/8.13.4/8.11.0) id q5JD614w397390 for adm; Tue, 19 Jun 2012 15:06:01 +0200
Date: Tue, 19 Jun 2012 15:06:01 +0200
From: daemon
Message-Id: <201206191306.q5JD614w397390@bluestar>
To: adm
Subject: Output from cron job /some/file/at/the/user/side/CronScript.ksh, adm@bluestar, exit status 0
Cron Environment:
 SHELL = /usr/bin/sh
 PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java14/jre/bin:/usr/java14/bin:/usr/java131/jre/bin:/usr/java131/bin
 CRONDIR=/var/spool/cron/crontabs
 ATDIR=/var/spool/cron/atjobs
 LOGNAME=adm
 HOME=/some/location/at/some/place
Your "cron" job executed on bluestar on Tue Jun 19 15:05:00 2012
/some/file/at/the/user/side/CronScript.ksh
 
produced the following output:
a /some/file/at/the/user/side/CronScriptCheck
a /other/file/at/the/user/side/testBackup.log 8038 blocks
a /some/file/at/the/user/side/CronScript.ksh 2 blocks
a /other/file/at/the/user/side/testBackup.log 8038 blocks
a /some/file/at/the/user/side/CronScriptCheck/net-sense.cron 1 blocks
/other/file/at/the/user/side/testBackup.log.tar: No such file or directory
chmod: CronScript.ksh: No such file or directory
****************************************************
Done with the logs backup and cleaning of the source file
DATE:
****************************************************
 
*************************************************
Cron: The previous message is the standard output
      and standard error of one of your cron commands.
 
 
 

---------- Post updated at 03:43 PM ---------- Previous update was at 03:17 PM ----------

Hi,

I executed the cron job from home directory.

Cron is also in the home directory.

Yes, I defined the current directory in my cron file and as well as for the tar also.

But, what I don't understand is that, when I am executing the Croncript.ksh directly I am getting the desired result. While doing the same with the help of cron I am not getting the desired result !

The cron job fails to tar and gzip the test.log file

Please have a look to the above post which I quoted from the mail message !

As a minimum the script needs a cd to the absolute path of your home directory. Either that or specify the full path to every filename you mention in the script (not just some of them).

Beware of creating files with the same name as unix commands. e.g. test . One day it will you grief.

The default environment for cron is quite limited.
Try making a one-off cron to enquire what the environment is like. In your case the current working directory was not your home directory.

echo "Current working directory"
pwd
echo "Environment variables"
env
/other/file/at/the/user/side/testBackup.log.tar: No such file or directory
chmod: CronScript.ksh: No such file or directory

you must define the full path in your script within as cronjobs