Re: parse an environment file

Discussion in 'Python' started by Dave Angel, Oct 1, 2012.

  1. Dave Angel

    Dave Angel Guest

    On 09/30/2012 08:11 PM, Jason Friedman wrote:

    First comment: I don't know anything about an "environment file." An
    environment is an attribute of a process, and it's inherited by
    subprocesses that process launches. This is not a Python thing, it's an
    OS thing, for whatever OS you're running.

    > $ crontab -l
    > * * * * * env
    >
    > This produces mail with the following contents:
    >
    > HOME=/home/spjsf
    > LOGNAME=spjsf
    > PATH=/usr/bin:/bin
    > PWD=/home/spjsf
    > SHELL=/bin/sh
    > SHLVL=1
    > USER=spjsf
    > _=/usr/bin/env


    In other words, these are the environment variables that cron has, and
    that it gives to any children it launches.

    > On the other hand
    >
    > $ env
    >
    > produces about 100 entries, most of which are provided by my .bashrc;
    > cron provides only a limited number of environment variables.


    Gee, those are variables specific to a particular (bash) shell, so how
    would a program launched by cron know about them?


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


    You'd have to change the environment that cron sees (before login), or
    add to the crontab, or /etc/default/cron, or else run some shell from
    cron that defines those variables and then runs the application. The
    way to do this is specific to whatever OS you're running, and is
    irrelevant to Python.

    Try googling. For some examples, none of which use Python:

    http://www.perlmonks.org/?node_id=624540
    http://www.unix.com/solaris/164483-environment-variables-cron.html
    http://www.computing.net/answers/unix/how-to-set-environment-variable/5689.html
    http://linuxshellaccount.blogspot.com/2007/10/crontab-and-your-environment.html

    --

    DaveA
     
    Dave Angel, Oct 1, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Friedman

    parse an environment file

    Jason Friedman, Oct 1, 2012, in forum: Python
    Replies:
    3
    Views:
    269
    Alain Ketterlin
    Oct 1, 2012
  2. Chris Angelico

    Re: parse an environment file

    Chris Angelico, Oct 1, 2012, in forum: Python
    Replies:
    0
    Views:
    267
    Chris Angelico
    Oct 1, 2012
  3. Jason Friedman

    Re: parse an environment file

    Jason Friedman, Oct 1, 2012, in forum: Python
    Replies:
    4
    Views:
    252
    Ramchandra Apte
    Oct 2, 2012
  4. Chris Angelico

    Re: parse an environment file

    Chris Angelico, Oct 1, 2012, in forum: Python
    Replies:
    0
    Views:
    261
    Chris Angelico
    Oct 1, 2012
  5. Chris Angelico

    Re: parse an environment file

    Chris Angelico, Oct 1, 2012, in forum: Python
    Replies:
    2
    Views:
    259
    88888 Dihedral
    Oct 1, 2012
Loading...

Share This Page