Wednesday, December 30, 2009

A cron script does not work - check mail in /var/spool/mail

I was really surprized when my cron script didn't work from cron. Though it successfully worked through at and has all neccessary environments.
Today I found a suggestion to add to /etc/crontab your own email address and investigate the output. I changed MAIL in the /etc/crontab, restarted crond by "service crond restart", but no messages in my mailbox. Then I returned MAIL=cron in the /etc/crontab and just checked root's mailbox in /var/spool/mail/cron. And I had found the reason - "sh: kinit: command not found"! Though I thought that all paths are presented in $PATH of cron-script :) After adding to PATH variable the /usr/kerberos/bin the script began to work via cron successfully.
Therefore don't forget to check mails in such cases!!!
Other experience said me that variable should be exported actually by export -
#!/bin/bash
PATH=$PATH:/bin:/sbin:/usr/bin:/usr/kerberos/bin/
export FIRST_V=mean1
export SECOND_V=mean2
....