Results 1 to 7 of 7
Hello, dear community
Please help if you know the answer for the following problem: How can i specify custom variables so that they will be recognized by programs which are ...
- 03-03-2008 #1Just Joined!
- Join Date
- Apr 2007
- Location
- St. Petersburg, Russia
- Posts
- 7
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 so that they will 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:
but it didn't help. Any ideas what could be the solution?Code:SHELL=/bin/bash USER=misha */30 * * * * /opt/sevzapmodis/pymodis.py >> /home/misha/pymodis.log
- 03-03-2008 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
show your Python script.
- 03-03-2008 #3Just Joined!
- Join Date
- Apr 2007
- Location
- St. Petersburg, Russia
- Posts
- 7
- 03-03-2008 #4Linux User
- Join Date
- Aug 2006
- Posts
- 458
i notice you have */30 * * * * in your cron
change that to
* * * * *
and see what happens.
- 03-03-2008 #5Just Joined!
- Join Date
- Apr 2007
- Location
- St. Petersburg, Russia
- Posts
- 7
In such way it only runs every minute instead of once per two minutes. Everything goes in the same way.
I have also tried to play with os.environ[] call:
At the outuput only two first lines appear.Code:import os logfile = open('/home/misha/pymodis.log','w') logfile.write(os.environ['USER']+'\n') logfile.write(os.environ['HOME']+'\n') logfile.write(os.environ['SEADAS']+'\n') # SEADAS is path to a directory'/etc/Seadas' in my ~/.bashrc logfile.write(os.environ['HOME']+'\n')
- 03-03-2008 #6Linux User
- Join Date
- Aug 2006
- Posts
- 458
i'm not sure really what you want. you can try change "w" to "a" in your open() statement if you need to log to a log file without overwriting the previous entries
- 03-04-2008 #7Just Joined!
- Join Date
- Apr 2007
- Location
- St. Petersburg, Russia
- Posts
- 7
I was just trying to see which variables will be recognized, and which won't be. Somehow if i wanted to write to a text file a variable value which is not recognized then everything else after it (like one more time value of a "HOME" variable) is not written as well. Weird, i have to study this behavior more. Or is there any obvious mistake of mine?
For now i managed with the problem via workaround, assigned all of the variables in the beginning of subscripts called by os.system(). But i still wonder, how can i pass values of some variables to a python script (a crontab entry) instead of writing it to subscripts...


Reply With Quote