# How to create a crontab file for user elasticsearch

**URL:** <https://discuss.elastic.co/t/how-to-create-a-crontab-file-for-user-elasticsearch/172107>\
**Category:** Elasticsearch\
**Created:** [March 13, 2019, 9:52am UTC](https://discuss.elastic.co/t/how-to-create-a-crontab-file-for-user-elasticsearch/172107 "2019-03-13T09:52:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PRUDHVI\_CHOWDHARY\_NE](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@PRUDHVI\_CHOWDHARY\_NE](https://discuss.elastic.co/u/PRUDHVI_CHOWDHARY_NE)\
**Post date:** [March 13, 2019, 9:52am UTC](https://discuss.elastic.co/t/how-to-create-a-crontab-file-for-user-elasticsearch/172107/1 "2019-03-13T09:52:02Z")

</div>

**I want to run a crontab job on elastic search docker image**

**here is my docker file**

[FROM [docker.elastic.co/elasticsearch/elasticsearch:6.6.0](http://docker.elastic.co/elasticsearch/elasticsearch:6.6.0)

ENV PATH=$PATH:/usr/share/elasticsearch/bin

RUN yum -y update

RUN yum -y install crontabs

RUN echo -e "root\nelasticsearch" \> /etc/cron.allow

RUN echo "" \>\> /etc/cron.allow

RUN chmod -R 644 /etc/cron.d

RUN cat /etc/cron.allow

RUN chown -R elasticsearch /etc/cron.d

RUN chmod -R 755 /etc/cron.d

RUN chown -R elasticsearch /var/spool/cron

RUN chmod -R 744 /var/spool/cron

RUN chown -R elasticsearch /etc/crontab

RUN chmod -R 744 /etc/crontab

RUN chown -R elasticsearch /etc/cron.d

RUN chmod -R 744 /etc/cron.d

COPY ./purge.sh /usr/share/elasticsearch

RUN ls -l /etc/crontab

RUN ls -l /etc/cron.d

RUN touch /usr/share/elasticsearch/cron.log

ADD ./cron /etc/cron.d/cron\_test

RUN chmod 0644 /etc/cron.d/cron\_test

RUN cd /etc/cron.d && cat cron\_test

RUN chown -R elasticsearch /etc/cron.d/cron\_test

RUN ls -l /etc/cron.d/cron\_test

#This will add it to the cron table (crontab -e)

RUN crontab /etc/cron.d/cron\_test

RUN crontab -l

RUN cd /var/spool/cron && ls

USER elasticsearch

ENTRYPOINT elasticsearch

CMD crond start && pgrep cron && tail -f && tail -f /usr/share/elasticsearch/cron.log

EXPOSE 9200 9300](http://)

**after running this docker file and executing the container**

 ![a1](https://us1.discourse-cdn.com/elastic/original/3X/5/c/5caff1869f5293f6bd2f43c1b8040e83bf5d7dba.png)

**in this step in docker file**  
RUN cd /var/spool/cron && ls

**it's showing only root , but how can i get elasticsearch user in it ?**

**my cron file present locally**  
\*/1 \* \* \* \* echo "Hello world" \>\> /usr/share/elasticsearch/cron.log  
\*/1 \* \* \* \* elasticsearch /usr/share/elasticsearch/purge.sh

**my purge.sh file**  
curl -XPOST "[http://localhost:9200/hydro\_dashboard\_index/\_delete\_by\_query](http://localhost:9200/hydro_dashboard_index/_delete_by_query)" -H 'Content-Type: application/json' -d'  
{  
"query": {  
"range" : {  
"query\_service\_entry\_time" : {  
"lt" : "now-14d"  
}  
}  
}  
}'

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 13, 2019, 6:32pm UTC](https://discuss.elastic.co/t/how-to-create-a-crontab-file-for-user-elasticsearch/172107/2 "2019-03-13T18:32:17Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.  
Please update your post.

I believe that your question is more a Docker question than an elasticsearch question. In which case I'd suggest asking in Docker forums instead.

---

<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:** [April 10, 2019, 6:32pm UTC](https://discuss.elastic.co/t/how-to-create-a-crontab-file-for-user-elasticsearch/172107/3 "2019-04-10T18:32:20Z")

</div>

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