Pergunta

I have a cron job on an IBM AIX server scheduled more or less like this:

0 6 * * * (date >> ~/executions.log;. ~/.profile; cd /usr/path/to/the/script; /usr/path/to/the/script/ThisIsTheScript.sh ) > /dev/null 2>&1

When I schedule a test run like this:

0,37 6 * * * (date >> ~/executions.log;. ~/.profile; cd /usr/path/to/the/script; /usr/path/to/the/script/ThisIsTheScript.sh ) > /dev/null 2>&1

...the job will only run up to the part where it appends the last execution date to ~/executions.log. Since this script calls a very huge application -- let's call it gargantuanprogram -- once the job fires it should show up on ps ax | grep gargantuanprogram. But it doesn't, and it doesn't even runs ThisIsTheScript.sh because said script sends out an e-mail notification when it starts, and on my mailbox I just get nada.

As you can see, yes, I'm loading my ~/profile, I checked many times that the script had execute permission, and I'm absolutely sure the line is written properly. The crontab is terminated with a newline too. Why is then the job not executing?

Foi útil?

Solução

Usually what I do is I have a script that works. I then wrap that script with another script to set things up for cron such as source .profile, redirecting stdout and stderr, logging errors, etc. I keep the entry in the crontab itself very simple and clean. Its just easier to muck with and debug.

Usually folks with issues like this have put something in their .profile that assumes a controlling tty is attached (like stty or something like that). Another thing I have in my .profiles is the ability to turn on tracing so I can see where the .profile loading is dying. Do this with "set -x". I actually have a tree of .profiles so I set a variable in the top one and which does the set -x if it is set.

The shell will not be interactive nor have a controlling tty. This is sorta rare and often confuses something in a user's .profile. The shell is probably "sh" which might have some subtle differences from /bin/ksh although it is not suppose to.

Hope this helps

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top