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 !
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...)
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