1

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?

masegaloeh
  • 17,978
  • 9
  • 56
  • 104

2 Answers2

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.

Ignacio Vazquez-Abrams
  • 45,019
  • 5
  • 78
  • 84
1

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.

peterh
  • 4,914
  • 13
  • 29
  • 44
Ma Diga
  • 51
  • 2