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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cron job is not working in the desired manner on IBM AIX
# 1  
Old 06-20-2012
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 :-
Code:
#!/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 !

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data

Last edited by vbe; 06-20-2012 at 05:26 AM..
# 2  
Old 06-20-2012
check the mail for cron messages and what it says ?
# 3  
Old 06-20-2012
could you please let me know where to check for the mail on IBM AIX ? As I am totally new to it !
# 4  
Old 06-20-2012
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...)
# 5  
Old 06-20-2012
Quote:
Originally Posted by acidburn_007
could you please let me know where to check for the mail on IBM AIX ? As I am totally new to it !
check the last mails for the actual time that you executed the cron job
Code:
# mail
& h $

and then for example the output
Code:
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
Code:
& 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                      ###


Last edited by ygemici; 06-20-2012 at 05:42 AM..
# 6  
Old 06-20-2012
i checked at the location /usr/spool/mail and got the following message :-

HTML Code:
 
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 !
# 7  
Old 06-20-2012
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Crontab - entry not working , cron job not running

I have put a cron entry in oracle user for taking hot backup every wednesday@ 2.30 AM and have given the cron entry 30 02 * * 3 /u01/vijay/hotbackupcron 2>&1 >> /u01/vijay/hotbackup.log also find below the script inside hotbackupcron, i have put in env variables as well ... (13 Replies)
Discussion started by: vijaymec50
13 Replies

2. AIX

Cron job not working but works on other nodes.

Hi All, I have a many cron jobs scheduled in my AIX server. Only one cron not getting executed in the same server but that job is good on all other servers. Here is my cron , which will keep last 30 files and remove others., 00 00 * * * /usr/bin/find /tmp/reports/nmon -name *.nmon -mtime... (9 Replies)
Discussion started by: Thala
9 Replies

3. UNIX for Dummies Questions & Answers

Cron job not working

cron process in AIX is there when I do ps -ef |grep cron, but none of cron job is working. It appears that cron process is hanging or having some issues? How do you resolve this? Do I kill the cron process by kill -9 PID? and how to start it? Please advise. (1 Reply)
Discussion started by: Daniel Gate
1 Replies

4. Shell Programming and Scripting

cron job now working?

Hi all, I wrote a script as below, #!/bin/ksh . /app/home/etc/sudo.profile >/dev/null java -jar $HOME/abc.jar The jar file abc.jar is located in the same folder as the script. When I'm manually running that script the jar file gets executed. However if I set a cron job, it... (5 Replies)
Discussion started by: isaacniu
5 Replies

5. Shell Programming and Scripting

cron job is not working for two scripts

Hi Gurus, I have a test unix server in which currently some unix cronjob are running. I have written two script one is a shell script in which env variable are there (in that i am exporting those variables). I have also written a perl script . when i am running at the shell manually like... (5 Replies)
Discussion started by: sanjay.login
5 Replies

6. Shell Programming and Scripting

HELP: I need to sort a text file in an uncommon manner, can't get desired results

Hi All I have a flat text file. Each line in it contains a "/full path/filename". The last three columns are predictable, but directory depth of each line varies. I want to sort on the last three columns, starting from the last, 2nd last and 3rd last. In that order. The last three columns... (6 Replies)
Discussion started by: JakeKatz
6 Replies

7. Shell Programming and Scripting

Sudo command not working with cron job.

Hello, I have written a script that has a sudo command to change file permissions within it. When I run the script manually, the sudo command inside of it works fine. When the script is run through crontab I get the error "cron: not found". It the same user profile that I am using... (6 Replies)
Discussion started by: WhotheWhat
6 Replies

8. Shell Programming and Scripting

cron job not working for some reasons

I set up a new cron job. I have set cron jobs many times in the past and never faced issues. For some reasons my new cron job is not working.This is how my cron job looks like. plz help me out guys. 3,8,13,18,23,28,33,38,43,48,53,58 * * * * /siebel/sblp900/home/FSMTaskChk/script... (14 Replies)
Discussion started by: ragha81
14 Replies

9. UNIX for Dummies Questions & Answers

Cron job not working

Hello, I have the following crontab entry that does not seem to be running. When I check /var/cron/log, it is not there. Here is my os info: SunOS birch 5.9 Generic_118558-09 sun4u sparc SUNW,Sun-Fire-V240 Here is the crontab entry: 01 21 * * * find /export/app/datafeed/flus/archive -mtime... (5 Replies)
Discussion started by: dkranes
5 Replies

10. Shell Programming and Scripting

Cron job not working

Hi All, I created a shell script and it works perfectly fine when I run from the command. But the same does not work as expected when I call it from a cron job. Here is the shell script(scan.sh): # # #Which directory to scan for files?... (7 Replies)
Discussion started by: janavenki
7 Replies
Login or Register to Ask a Question