[go: up one dir, main page]

Unable to set env vars per job

Created by: nnashok

I want to set env vars to specific values for my jobs, something like:

CRON_TZ="America/Los_Angeles"
* 15 * * * echo "LA: $(date)"

CRON_TZ="America/New_York"
*/2 18 * * * echo "NY: $(date)"

However, the package ends up retaining only the last value of the env var and persisting that in the crontab, effectively removing the customization for the jobs. The following example code illustrates the issue:

from crontab import CronTab
import sys

cron = CronTab(tabfile='output.tab')

cron.env['CRON_TZ'] = 'America/New_York'
job  = cron.new(command='/usr/bin/echo "new york"')
job.setall(1, 12, None, None, None)

cron.env['CRON_TZ'] = 'America/Los_Angeles'
job  = cron.new(command='/usr/bin/echo "los angeles"')
job.setall(1, 23, None, None, None)
cron.write( 'output.tab' )

The output is:

CRON_TZ=America/Los_Angeles
1 12 * * * /usr/bin/echo "new york"
1 23 * * * /usr/bin/echo "los angeles"

instead of:

CRON_TZ=America/New_York
1 12 * * * /usr/bin/echo "new york"
CRON_TZ=America/Los_Angeles
1 23 * * * /usr/bin/echo "los angeles"