Tuesday, 17 May 2016

Question : Different mail from shell script and cron running the script

Question posted on stackexchange:


I have a perl script that executes a command. I am saving the output of this command to an array and checking the content on the output to mail me a success or a failure message.

This works fine when i run the script itself. But when i schedule the script to run as a cronjob i get a failure mail irrespective of the output.

I am using all the abs paths in script and know the cron is executing since i see in my logs that the command is executed successfully.

Can someone tell me why the difference?
One thing to notice is, the command takes about a minute to finish executing and the script is waiting till the command is executed to check the output. So i am seeing a little delay in the mail when i run the script. But in the cron, i get a mail immediately at the run time. I am assuming the cron isn't waiting for the command to execute and check the output.
Could that be the case?


While running from crontab you cannot rely upon any environment variables, TTY, or paths. Sounds like you've got paths sorted but the mailer may be expecting to know something about you. Try running your script without your environment, to get meaningful messages about what your problem is: su {your_name} -c {your script}

No comments:

Post a Comment