Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm facing a weired problem on a unix-based machine. Here is the story: 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?

Thank you

share|improve this question

2 Answers 2

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 * * * * path_to_script.sh > /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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.