LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-03-2008, 05:12 AM   #1
itmi
LQ Newbie
 
Registered: Mar 2008
Posts: 2

Rep: Reputation: 0
Program initiated via python's os.system() doesn't work (when in crontab script)


Hello, dear community

Please help if you know the answer for the following problem: How can i specify custom variables to be recognized by programs which are executed by "os.system()" in python?

I have a python script which executes several programs via os.system() call. It runs fine when i execute it manually from interactive shell (bash), but when i put it in crontab it some of those programs don't work since they don't find several special environment variables that are present in my .bashrc file.

Trying to figure the problem out i have put two lines in the beginning of my crontab file, so that it looks like this:

Code:
SHELL=/bin/bash
USER=misha
*/30 * * * * /opt/sevzapmodis/pymodis.py >> /home/misha/pymodis.log
but it didn't help. Any ideas what could be the solution?
 
Old 03-03-2008, 08:56 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

The file .bashrc is usually for interactive shells. Mine starts with:

Code:
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
So sourcing it will not work. But why not add the special environment variables to start the crontab?

Code:
SHELL=/bin/bash
USER=misha
SOMESPECIALVARIABLE=SomeValue
*/30 * * * * /opt/sevzapmodis/pymodis.py >> /home/misha/pymodis.log
 
Old 03-03-2008, 01:08 PM   #3
itmi
LQ Newbie
 
Registered: Mar 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks, Guttorm. I've tried it exactly the way you have suggested, but it didn't work somehow. Next step was to set via "os.environ[]" but with the same negative result.

For now i have resolved it via assigning variables right in that (sub)script invoked by python, but i am still confused why it doesn't work the way Guttorm suggests...

Last edited by itmi; 03-04-2008 at 12:24 AM.
 
Old 03-03-2008, 05:36 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Try this: http://www.adminschoice.com/docs/cro...tm#Environment
 
  


Reply

Tags
bash, environment variable, python



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep does not work in crontab script blizunt7 Linux - General 5 08-24-2007 02:19 PM
Script doesn't execute in crontab jis0501 Linux - General 2 08-04-2007 07:09 AM
Command for executing C program in crontab bhandu Linux - Newbie 1 07-14-2007 12:54 PM
want to run program every minute, crontab???? poj Linux - General 4 09-19-2005 04:29 PM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 12:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration