Cronjob not working from user's crontab

Hi All,

I am trying to execute a python script from a user's crontab.

/home/user1/UDE/scripts/UdeManager.py

I am at /home/user1.

If I run the command "/home/user1UDE/scripts/UdeManager.py" from the users home directory its working fine.

But when I try to run from user's cron tab its giving some syntax errors.

crontab entry of the user1

*/1 * * * * /home/user1/UDE/scripts/UdeManager.py >> /tmp/2k.log1 2>&1

Error log from cron

Traceback (most recent call last):
  File "/home/user1/UDE/scripts/UdeManager.py", line 12, in ?
    import UdeUtilService
  File "/home/user1/UDE/scripts/UdeUtilService.py", line 164
    output = dict((str(k), [i[1] for i in outlst if i[0] == k]) for k in frozenset(j[0] for j in outlst))
                                                                  ^
SyntaxError: invalid syntax

Any help would be greatly appreciated.

The environment variables, PATH variable, etc., are not the same in the cron job as they are for the user when he/she logs in.

It is analogous to the difference between

su user1

and

su - user1

If that file is not in /home/user1 it is not going to be found.
First reaction is to specify the full path.
However because it works for user1 I would find out why it works, then compare the environment of the user to that of cron for that user.

Try comparing the output of "set" at the command prompt to the same command when run from a one-off cron. Particular attention to PYTHONPATH and more.

In the end you will probably need a shell wrapper to set enough environment variables to give Python the right environment.

Issue:Python script was working fine from command line not from crontab

Reason: Environment variables are not set in cron

#Redirect the environment variables of the user to a file.

$env > /home/user1/.env_file

$vi /home/user1/.env_file

#type "export" each variable mentioned over there.

export HOME LD_LIBRARYPATH

$vi myscript.sh

#Add the following line

source ~/.env_file

-------------

#script details

--------------
$crontab -e

#Crontab entry

*/1 * * * * /home/user1/myscript.sh > /tmp/logfile1 1>&2

---------- Post updated at 12:48 AM ---------- Previous update was at 12:46 AM ----------

I found the solution myself. Thanks a lot for the comments. I've posted the steps followed for future reference.