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 +30 -exec rm {} \\;

Note: The scripts works if executed manually.

Please Help me out!

try redirecting the cron entry to a log and see if any error is being captured .

Zozoo,

I tired but the log file is empty

55 15 * * * /usr/bin/find /tmp/reports/nmon -name  *.nmon -mtime +30 -exec rm {} \\ >> mybug.log

if i manually execute this command i am able to find the files

/usr/bin/find /tmp/reports/nmon -name  *.nmon -mtime +30

Any suggestion?

Hello Thala,

Could you please try to put the code in a script and then try to put it in Cron tab.

Thanks,
R. Singh

try giving the

2>&1

to capture the error and also ...can you try to enclose the whole command with in

()

---------- Post updated at 07:42 PM ---------- Previous update was at 07:27 PM ----------

found some information which can be useful

cron will email you the output of any program it runs (if there is any output). So, if you don't get any output, there are basically three possibilities:

crond could not even start a shell for running the program or sending email
crond had troubles mailing the output, or the mail was lost.
the program did not produce any output (including error messages)

Case 1. is very unlikely, but something should have been written in the cron logs. Cron has an own reserved syslog facility, so you should have a look into /etc/syslog.conf (or the equivalent file in your distro) to see where messages of facility cron are sent. Popular destinations include

/var/log/cron, /var/log/messages

and

/var/log/syslog.

In case 2., you should inspect the mailer daemon logs: messages from the Cron daemon usually appear as from

root@yourhost

. You can use a

 MAILTO=... 

line in the crontab file to have cron send email to a specific address, which should make it easier to grep the mailer daemon logs. For instance:

In case 3., you can test if the program was actually run by appending another command whose effect you can easily check: for instance,

00 15 * * * /a/command; touch /<some -path>/sucessfullrun

so you can check if crond has actually run something by looking at the mtime of /<some -path>/sucessfullrun

I would suggest that the shell is expanding the *.nmon in the current directory before trying to execute the command.

Try this to pass the wild-card value straight through to the find command:-

55 15 * * * /usr/bin/find /tmp/reports/nmon -name  "*.nmon" -mtime +30 -exec rm {} \; >> mybug.log 2>&1

I have corrected the \\ into \; and captured the errors too.

Of course, you are assuming that it is being called at all. Consider stoping your cron process. It should re-start and re-read your crontab file. You are editing the file with crontab -e aren't you? Changing the clock can also upset the cron process.

I hope that this helps.

Robin,
Liverpool/Blackburn
UK

Hi Robin,
I tried your script its working fine manually again !
but when i execute in crontab, it is not executing ! and the log file is also empty.

Yes , i am using crontab -e , hope i dont need to refresh the cron as i was saving the file after editing though it will auto refresh.

You could try putting it into teh background with '&' (no quotes), solved a similar issue I had once.

R.Singh,
I tried executing the code as a script file in CRON its working fine. Thanks.

So why this server alone not reading this command in command?

---------- Post updated at 05:29 PM ---------- Previous update was at 05:21 PM ----------

You want me to run this in normal shell or in cron ?

I would not worry about restarting cron on AIX. You will find that it is defined as a respawn process in /etc/inittab, so if you kill it off, the init process will start another.

What do you get in mybug.log by the way? Is this from the command line, a cron run of a script or a cron run of the command, or is that not firing at all?

Robin