PDA

View Full Version : One cron job doesnt work correctly



tzwaj
08-Jan-2015, 12:25
Hi

All jobs are working but not the latest.
It starts a script that produces a file. But the file is empty if i run it from cron, but if i run it manually in the same way as it is written in cron it works.

10 12 * * * /home/admin/bin/lic-print.sh

I have tried with
10 12 * * * root /home/admin/bin/lic-print.sh doesnīt work

If i run it from prompt with /home/admin/bin/lic-print.sh it works, doesnīt matter if i run it as root or admin.

File properties:
-rwxrwxr-x 1 admin root 1185 Jan 8 12:02 DEN-lic.txt

Any suggestions why?

blaube
08-Jan-2015, 12:53
Hello,

does the script need any special environment variables?

You can check the root mails. If the script returns any error, cron often sends
an e-mail to the user account.

Bye
Simone Truschko

tzwaj
08-Jan-2015, 14:01
Found the problem, when running as crontab you need to have the whole path to the command in the script, but you donīt need it running outside, why, i donīt know. It works :-)

blaube
09-Jan-2015, 13:37
Perhaps your path varible is not exported.
That is why I ask about the environment.
The environment in cronjobs is other than on the console.

jmozdzen
12-Jan-2015, 15:39
Hi tzwaj,


Found the problem, when running as crontab you need to have the whole path to the command in the script, but you donīt need it running outside, why, i donīt know. It works :-)

cron jobs are run by the cron daemon, which is started upon boot and uses the environment set at that time. IOW, it has a limited environment and any user-specific settings *are not part of it*. It has nothing to do with "export"ing variables as a user.

You can either set up your own PATH inside your script, or fully reference the binaries outside the standard path (as you did). To check the environment context provided by cron, simply start a cron job that redirects the output of the "env" command to a file...

Regards,
Jens