0
votes

I have been writing housekeeping script , now i need to install housekeeping script as a cronjob on both staging and production environment. i could do it on the staging without a problem and it gives me expected output. when i run it on the production, same script does not turn as a cronjob.following is the cronjob i installed.

#OTB housekeeper scripts
* * * * * /product/susara/tools/housekeeper.sh -t OTB > /tmp/susara.out 2>&1

this is what i did to find out why it is not working on production

  1. check whether cronjob daemon is running. when i check it, got the following output and, which says cronjob deamon is running

ps ax|grep cron

output

 4120 ?        Ss     0:06 crond
13640 pts/6    S+     0:00 grep cron
  1. checking the cron job logs

these logs were located in the /log/var there are log files named cron cron.1 cron.2 etc.

content of these logs does not give my any help to solve the issue. i am difficult to understand what it says.

May 16 08:01:01 pr2vmx08 crond[17471]: (root) CMD (run-parts /etc/cron.hourly)
May 16 08:08:22 pr2vmx08 crontab[17180]: (user1) REPLACE (user1)
May 16 08:08:22 pr2vmx08 crontab[17180]: (user1) END EDIT (user1)
May 16 08:09:01 pr2vmx08 crond[4162]: (user1) RELOAD (cron/user1)
May 16 08:10:01 pr2vmx08 crond[17762]: (root) CMD (/usr/lib64/sa/sa1 1 1)
May 16 08:20:01 pr2vmx08 crond[18229]: (root) CMD (/usr/lib64/sa/sa1 1 1)

These two steps did not help me to solve the issue. could anybody having some experince in this area let me know what is going wrong here.

Thanks in advance for any help

2
Do some searching here on SO, this question pops up quite frequently... Remember that the environment is completely different when running the script via cron than compared to running it as yourself... - Fredrik Pihl

2 Answers

1
votes

There are some things I would check first:

  1. What is the content of file /tmp/susara.out? Is this file being written at all? Use command

    tail -f /tmp/susara.out

    to see what is being written to this file;

  2. Check permissions for your script, /product/susara/tools/housekeeper.sh under production machine; use command

    ls -al /product/susara/tools/housekeeper.sh

  3. Is this script supposed to be running every minute?

  4. Check for possible error messages on file /var/log/messages

Regards

1
votes

The cron logs indicate date, machine name, process and some kernel "pid" of sorts between brackets, then user between parenthesis, and the command line between parenthesis, after "CMD".

If you grep your script name you should see some lines if it's being executed every minute, as it should, given the all-asterisk parameters. But perhaps the "correct" log file(s) would be syslog(.*), but maybe not, as this one apparently is already logging cron.

Additionally, I think that if this script includes calls to commands or other scripts that aren't in the standard PATH environment variable, it may not work properly/at all. It was happening to me with my "user" crontab, I added the correct PATH line in the crontab, and it started to work. I had the impression that I had to actually restart cron, with this particular change, unlike simple changes in the normal scheduling lines.