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
  • 18,236
  • 10
  • 57
  • 106

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,939
  • 6
  • 79
  • 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,953
  • 13
  • 30
  • 44
Ma Diga
  • 151
  • 2