Executing python scripts via cron job


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Executing python scripts via cron job
# 1  
Old 03-09-2012
Executing python scripts via cron job

Hi,

I'm executing a python script via cron job. The way it is set up is, I'm editing a file called local[ inside /etc/cron.d/.The local file content is as follows:

Code:
00 22 * * * root su - -c "/opt/setup_dir/bin/run_bkp -p"

When this job executes, the command-specific logfile and the syslog (where the logs are supposed to go) show half of the logs(no errors) and the command (and also the child cron) gets terminated in the midway(checked it with ps -ef | grep su and same way for the child cron) without deleting the lock files(which it is normally supposed to do even on an abnormal termination).

I browsed for this issue and found the suspect might be the way stdout(print in python) is handled in cron! To confirm, i just executed another python script that logs to logfile and also prints to console. It gave me the same failure.

But if I change the content of the local file to

Code:
00 22 * * * root su - -c "/opt/setup_dir/bin/run_bkp -p > /root/cronlog"

it works just fine. The process completes gracefully with all the cleanup actions done and logs updated.

But i still do not understand so clearly what was exactly the issue, can someone explain if it is known to you? And also the MAILTO field in /etc/crontab file is empty ("").I'm hoping this is the default path where we get the cron logs as mails . Will it help to solve this if i change this filed? (pls let me know what to populate this with)

Kindly suggest the best solution for this.
# 2  
Old 03-09-2012
if the process is schedules on root then ucan simplewrite

00 22 * * * /opt/setup_dir/bin/run_bkp -p > /root/cronlog

you can read /var/mail/root file to identify error
This User Gave Thanks to dodasajan For This Post:
# 3  
Old 03-12-2012
python module issue?

Sadly that didn't workSmilie. The user field seems to be compulsory.

But I found something here. In my python script, the python module used for writing into syslog and console is the "logger" module. I noticed that most of the scripts that uses this are showing the behaviour mentioned above. But the scripts that use python "syslog" modules for the same works all fine. I'm trying to make out the exact difference between these but meanwhile, Just wanted to know if I'm in the right direction to investigate the issue. So if anyone is aware if this might cause such issues, pls comment.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

2. Shell Programming and Scripting

Commented cron job -- cron monitoring

Hi I have a requirement to write a shell script,that will check the all commented job in cron job.Please help !! (2 Replies)
Discussion started by: netdbaind
2 Replies

3. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

4. Shell Programming and Scripting

cron job is not working for two scripts

Hi Gurus, I have a test unix server in which currently some unix cronjob are running. I have written two script one is a shell script in which env variable are there (in that i am exporting those variables). I have also written a perl script . when i am running at the shell manually like... (5 Replies)
Discussion started by: sanjay.login
5 Replies

5. Shell Programming and Scripting

Cron job not executing

I need to add 10 records to database from a file /tmp/authlist.log(contains insert into table sql commands) When i execute the following script manually its executing and working fine. the same is not getting executed when i try to execute using crontab vi /tmp/test1.sh #!/bin/sh... (4 Replies)
Discussion started by: kalyankalyan
4 Replies

6. UNIX for Dummies Questions & Answers

Problem with executing command inside a cron job

Hi All, I have scheduled a script in cron which writes output to the below file. ....>> /data/Target/wrapper_invoke_ds_job_`date '+%Y%m%d'`.ksh_out 2>&1 But the date command is not getting resolved in the format specified. It just resolves to the following. wrapper_invoke_MQ_ds_job_Tue... (3 Replies)
Discussion started by: pkm_oec
3 Replies

7. Shell Programming and Scripting

Running scripts within scripts from cron

Hi all, I have set up a cron job which calls another shell script shell script which in turn calls a Java process. The cron tab looks so. 0,30 7-18 * * 1-5 /u01/home/weblogic/brp/bin/checkstatus.sh >> /u01/home/weblogic/logs/checkstatus.log The checkstatus.sh scripts looks like this. ... (4 Replies)
Discussion started by: sirbrian
4 Replies

8. Solaris

cron job starts new cron proccess

I run cron in solaris 10 zone. One cron job which syncing files to nfs mounted on container, creates after finishing another cron proccess(/usr/sbin/cron), and after 100 existing cron proccesses next cron job will not start. It's too weird for me, I'm not able to solve this problem. Theoretically... (3 Replies)
Discussion started by: ron76
3 Replies

9. UNIX for Dummies Questions & Answers

CRON usage for CRON job

can anybody explain the usage of CRON for adding a cron job. please provide an example also for better understanding !!! Thanks (1 Reply)
Discussion started by: skyineyes
1 Replies

10. UNIX for Dummies Questions & Answers

CRON job to execute all scripts in a directory

Hi everyone: I'm trying to make a CRON job that will execute Fridays at 7am. I have the following: * 7 * * 5 I've been studying up on CRON and I know to have this in a file and then "crontab filename.txt" to add it to the CRON job list. The CRON part I believe I understand, but I would... (6 Replies)
Discussion started by: Annorax
6 Replies
Login or Register to Ask a Question