# While using enviroment variable in Curator -crontab.Unable to get required output

**URL:** <https://discuss.elastic.co/t/while-using-enviroment-variable-in-curator-crontab-unable-to-get-required-output/229302>\
**Category:** Elasticsearch\
**Tags:** curator\
**Created:** [April 22, 2020, 3:29pm UTC](https://discuss.elastic.co/t/while-using-enviroment-variable-in-curator-crontab-unable-to-get-required-output/229302 "2020-04-22T15:29:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dragon9](https://avatars.discourse-cdn.com/v4/letter/d/7bcc69/32.png) [@Dragon9](https://discuss.elastic.co/u/Dragon9)\
**Post date:** [April 22, 2020, 3:29pm UTC](https://discuss.elastic.co/t/while-using-enviroment-variable-in-curator-crontab-unable-to-get-required-output/229302/1 "2020-04-22T15:29:43Z")

</div>

i set enviroment variable for elasticsearch-service in curator's config yml. and some env var in action\_file.yml

i export variable in bash\_profile file and other solution found in web but it does not work

there are two scenerio  
1.when i run manually i.e.  
curator --config /etc/config/config.yml /etc/config/action\_file.yml \>\> /var/log/curator-(date +\%d\%b\%y\_\%H\%M\%S).log then it works as expected 2.when i run with crontab i.e. 0 \* \* \* \* curator --config /etc/config/config.yml /etc/config/action\_file.yml \>\> /var/log/curator-(date +%d%b%y\_%H%M%S).log  
error in logs

```auto
ERROR Schema error: Configuration: filter: Location: Action ID "1", action "delete_indices", filter #1: {'filtertype': 'age', 'timestring': '%Y.%m.%d', 'direction': 'older'}: Bad Value: "(could not determine)", required key not provided @ data['source']. Check configuration file.

```

how to solve this issue of running crontab with using enviroment var in curator

---

<div class="post-metadata">

**Author:** ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)\
**Post date:** [April 22, 2020, 4:55pm UTC](https://discuss.elastic.co/t/while-using-enviroment-variable-in-curator-crontab-unable-to-get-required-output/229302/2 "2020-04-22T16:55:45Z")

</div>

This is typically because `PATH` and other environment variables that you normally have access to from the command-line are not automatically passed through to cron.

My personal recommendation is to make your one-liner into a simple shell script, and then have cron call that. Tweak it until all of the paths etc. are fully functional.

---

<div class="post-metadata">

**Author:** ![Dragon9](https://avatars.discourse-cdn.com/v4/letter/d/7bcc69/32.png) [@Dragon9](https://discuss.elastic.co/u/Dragon9)\
**Post date:** [April 23, 2020, 1:19pm UTC](https://discuss.elastic.co/t/while-using-enviroment-variable-in-curator-crontab-unable-to-get-required-output/229302/3 "2020-04-23T13:19:45Z")

</div>

I did what you told me but the problem is still coming up.  
i made a demo.sh file

```auto
#!/bin/bash
curator --config /etc/config/config.yml /etc/config/action_file.yml >> /var/log/curator-(date +%d%b%y_%H%M%S).log

```

in crontab file

```auto
* * * * * sh /demo.sh

```

in config.yml

```auto
config.yml: |
    # Remember, leave a key empty if there is no value. None will be a string,
    # not a Python "NoneType"
    client:
        hosts:
        - ${ES_SVC}

```

means that crontab run the demo.sh file but unable to fetch the value of enviroment variable

---

<div class="post-metadata">

**Author:** ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)\
**Post date:** [April 23, 2020, 5:05pm UTC](https://discuss.elastic.co/t/while-using-enviroment-variable-in-curator-crontab-unable-to-get-required-output/229302/4 "2020-04-23T17:05:24Z")

</div>

Yes, which means you need to find a way to source those environment variables in your script. I'm sorry I wasn't more clear on that front.

`cron` _cannot_ make use of arbitrary environment variables. They have to be declared in order to pass them to some script, or the script must source them.

Ways of doing this include a second file which has something like:

```auto
ENVVARNAME=VALUE; export ENVVARNAME

```

and then in your script, you would use

```auto
source /path/to/other_filename

```

and then you could use `${ENVVARNAME}` in your script.

---

<div class="post-metadata">

**Author:** ![Dragon9](https://avatars.discourse-cdn.com/v4/letter/d/7bcc69/32.png) [@Dragon9](https://discuss.elastic.co/u/Dragon9)\
**Post date:** [May 1, 2020, 3:05pm UTC](https://discuss.elastic.co/t/while-using-enviroment-variable-in-curator-crontab-unable-to-get-required-output/229302/5 "2020-05-01T15:05:57Z")

</div>

@theuntergeek  
thanks for your solution  
one more issue is there  
if i make a enviroment variable for action file.

my action.yml

```auto
1:
        action: delete_indices
        description: >-
          Delete indices older than (based on index name), for
          prefixed indices. Ignore the error if the filter does not result in an
          actionable list of indices (ignore_empty_list) and exit cleanly.
        options:
          ignore_empty_list: True
          disable_action: False
        filters:
          - filtertype: pattern
            kind: regex
            value: '^(testing-).*$'
          - filtertype: age
            timestring: '%Y.%m.%d'
            source: name
            direction: older
            unit: days
            #unit_count: 4
            unit_count: ${RETENTION_PERIOD_FOR_TESTING}

```

my script where enviroment variable exported is - env-var.sh

```auto
#!/bin/bash
ES_SVC=${ES_SVC}; export ES_SVC
RETENTION_PERIOD_FOR_TESTING= ${RETENTION_PERIOD_FOR_TESTING}; export RETENTION_PERIOD_FOR_TESTING

```

with this configuration if i launch application following error throw by curator

```auto
2020-05-01 23:57:01,865 ERROR Schema error: required key not provided @ data['unit_count']
2020-05-01 23:57:01,865 ERROR Schema error: Configuration: filter: Location: Action ID "2", action "delete_indices", filter #2: {'filtertype': 'age', 'timestring': '%Y.%m.%d', 'source': 'name', 'direction': 'older', 'unit': 'days'}: Bad Value: "(could not determine)", required key not provided @ data['unit_count']. Check configuration file.

```

how to solve this please help

---

<div class="post-metadata">

**Author:** ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)\
**Post date:** [May 4, 2020, 11:17pm UTC](https://discuss.elastic.co/t/while-using-enviroment-variable-in-curator-crontab-unable-to-get-required-output/229302/6 "2020-05-04T23:17:56Z")

</div>

> [@Dragon9](#):
>
> RETENTION\_PERIOD\_FOR\_TESTING= ${R

There appears to be a space after the `=`, which is not acceptable in shell scripting. Could it be that?

---

<div class="post-metadata">

**Author:** ![Dragon9](https://avatars.discourse-cdn.com/v4/letter/d/7bcc69/32.png) [@Dragon9](https://discuss.elastic.co/u/Dragon9)\
**Post date:** [May 5, 2020, 7:21am UTC](https://discuss.elastic.co/t/while-using-enviroment-variable-in-curator-crontab-unable-to-get-required-output/229302/7 "2020-05-05T07:21:38Z")

</div>

@theuntergeek  
thanks for your reply  
as you told me to do

```auto
RETENTION_PERIOD_FOR_TESTING=${RETENTION_PERIOD_FOR_TESTING}; export RETENTION_PERIOD_FOR_TESTING 

```

but no success

---

<div class="post-metadata">

**Author:** ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)\
**Post date:** [May 5, 2020, 2:23pm UTC](https://discuss.elastic.co/t/while-using-enviroment-variable-in-curator-crontab-unable-to-get-required-output/229302/8 "2020-05-05T14:23:11Z")

</div>

So, that means that there is no value being passed—which, at closer look, is kind of not surprising:

```auto
ES_SVC=${ES_SVC}; export ES_SVC

```

How exactly can you pass the value of `ES_SVC` to itself? or `RETENTION_PERIOD_FOR_TESTING` to itself? You ought to be passing values to the environment variables. Here, you're passing the _value_ of variables—which may or may not be set properly—to identically named variables. This would make it nearly impossible to cleanly troubleshoot.

At the very least, you should change the variable names to not be identical.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 2, 2020, 2:23pm UTC](https://discuss.elastic.co/t/while-using-enviroment-variable-in-curator-crontab-unable-to-get-required-output/229302/9 "2020-06-02T14:23:13Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
