parse an environment file

Ulrich Eckhardt ulrich.eckhardt at dominolaser.com
Mon Oct 1 06:00:04 EDT 2012


Am 01.10.2012 02:11, schrieb Jason Friedman:
> $ crontab -l
> * * * * * env
>
> This produces mail with the following contents:
>
[...]
> SHELL=/bin/sh
         ^^^^^^^
[...]
>
> On the other hand
>
> $ env
>
> produces about 100 entries, most of which are provided by my .bashrc;

bash != sh

Instead of running a script in default POSIX shell, you might be able to 
run it in bash, which will then read your ~/.bashrc (verify that from 
the docs, I'm not 100% sure). Maybe it is as easy as changing the first 
line to '#!/bin/bash'.

> I want my python 3.2.2 script, called via cron, to know what those
> additional variables are.

To be honest, I would reconsider the approach. You could patch the cron 
invokation, but that still won't fix any other invokations like starting 
it from a non-bash shell, filemanager, atd etc. You could instead set 
these variables in a different place that is considered by more 
applications. I wonder if maybe ~/.profile would be such a place.

Alternatively, assuming these environment variables are just for your 
Python program, you could store these settings in a separate 
configuration file instead. Environment variables are always a bit like 
using globals instead of function parameters.


Good luck!

Uli




More information about the Python-list mailing list