Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I have a personal username/password on a unix machine with limited privileges. Whenever I need to execute some commands I have to substitute user using the su command, then I execute it normally.

Now, I need to add a cronjob that uses such privileged commands so I added the cronjob on the crontab of the user I substituted to in order to have access to these commands.

Strangely, it turned out to me that these commands fail to run for some reason as a cronjob although when I execute them directly from shell (after su) they work seamlessly.

Why does this happen? Why do these commands not work as part of cronjobs?

share|improve this question

marked as duplicate by masegaloeh, Sam, peterh, Michael Hampton May 10 '15 at 14:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

They probably expect some environment variable to be set somehow, but it isn't when the command is run directly as that user. Usually $PATH.

share|improve this answer
could you please elaborate more. Thank you – Anonymous May 11 '10 at 7:26
I'm... not really sure how you want me to elaborate. Look at your environment variables. See if they matter. – Ignacio Vazquez-Abrams May 11 '10 at 7:42

I would add an output file to your cron entry so you can see why it failed to execute. i.e:

*/5 * * * * > /tmp/myscript.out 2>&1

After 5 minutes, check /tmp/myscript.out and see what it's complaining about.

Of course it would help finding out if you have the permission to create crons in the first place.

share|improve this answer