Cronjob not working from user's crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cronjob not working from user's crontab
# 1  
Old 02-10-2011
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

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

Error log from cron

Code:
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.

Last edited by Tuxidow; 02-10-2011 at 05:56 AM..
# 2  
Old 02-10-2011
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
Code:
su user1

and
Code:
su - user1

# 3  
Old 02-10-2011
Quote:
import UdeUtilService
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.
# 4  
Old 02-11-2011
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.
Code:
$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

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

Code:
$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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PHP cronjob not working but manual working

Hi, Can anyone help me on my PHP cron not working, but when i do the manual it work. # manual run working /usr/local/bin/php /root/dev/test.php # crontab not working 55 8 * * * /usr/local/bin/php /root/dev/test.php Thank in advances Regards, FSPalero Please use CODE tags as... (2 Replies)
Discussion started by: fspalero
2 Replies

2. Shell Programming and Scripting

Cronjob is NOT working

Hi; Here is the output from crontab -l: 2,7,12,17,22,27,32,37,42,47,52,57 * * * * /var/tmp/gcsw/jmap_samples/jmap_script.sh > /var/tmp/gcsw/jmap_samples/histo_`date '+%Y%m%d%H%M'`.txtWhen I manually run the line: /var/tmp/gcsw/jmap_samples/jmap_script.sh >... (2 Replies)
Discussion started by: gc_sw
2 Replies

3. Shell Programming and Scripting

Cronjob not working as intended

I have a shell script that I have scheduled using cron using a command: 0 10 * * * /directory/Script.sh > /directory/log/output.log The script is scheduled to run at 10 AM everyday. The script executes but produces output files only with headers, no content is there. The script produces... (11 Replies)
Discussion started by: Palak Sharma
11 Replies

4. UNIX for Dummies Questions & Answers

Cronjob not working

Hi, I am trying to run a script through crontab but it doesn't run. The script sends an email of the logfile created.When I reun through command line it works perfectly but doesn't send any email through cron. There are othe jobs in cron wich runs perfectly. Please let me know if I am doing... (3 Replies)
Discussion started by: Rossdba
3 Replies

5. Shell Programming and Scripting

crontab: setup cronjob to run first wednesday of every month

Hi, How to setup cronjob to run first wednesday of every month. Is there a way? Thanks.. (9 Replies)
Discussion started by: Anjan1
9 Replies

6. Red Hat

Cronjob not working at user timezone

I have created user and set timezone different from root user timezone in .bash_profile of user using TZ command, i have created cronjob for user using crontab -e, my concern is that job schedule in cronjob must executive as per timezone of user , but i am getting that job schedule in cron of user... (6 Replies)
Discussion started by: Mahenaaz
6 Replies

7. Solaris

cronjob not working

Hi All , I have a cron jobs that is not working while put inside cron. But on executing from manually, it works fine, Pl anyone find if there is anything wrong in the script. 30 22 * * 1-5 cd /home/ab90737/introscope/util/bin; ./batchgenerateReport.pl ../config/reps.config >... (1 Reply)
Discussion started by: jegaraman
1 Replies

8. Solaris

cronjob not working

I am trying to schedule a job via cronjob. Not sure what the problem is. below is my script and the error. 45 10 * * * /u01/app/oracle/jpark/sched_exp_mis.sh Error received. Your "cron" job on tama /u01/app/oracle/jpark/sched_exp_mis.sh produced the following output: ... (19 Replies)
Discussion started by: mrx1350
19 Replies

9. Shell Programming and Scripting

Cronjob Crontab Cron Restarter Help

Hello. I'd like to know how to make a simple restarter using cron. I made something like this: "* * * * * root home/..(full path)/file" But it doesn't work. How can I do that or how to make restarter of the application in other way? (1 Reply)
Discussion started by: ArtuDitu
1 Replies

10. UNIX for Advanced & Expert Users

cronjob not working

I created a file in /u01/oradata directory as cronjb.ksh which contains following script 30 12 * * * /export/home/oracle/u01/oradata/rman.ksh '/export/home/oracle' is my root directory. I then moved cronjb.ksh file to my '/export/home/oracle' directory. i typed crontab cronjb.ksh. However my... (8 Replies)
Discussion started by: manna
8 Replies
Login or Register to Ask a Question