# cat clean_log.sh
##################################################################
#!/bin/sh
#删除ELK30天前的日志
while true
do
DATE=`date -d "30 days ago" +%Y.%m.%d`
Xs=`curl -s -X GET http://xx.xx.xx.xx:9200/_cat/indices?v| grep $DATE | awk -F '[ ]+' '{print $3}'`
for X in ${Xs[@]}
do
curl -s -X DELETE "http://xx.xx.xx.xx:9200/$X"
done
sleep 24h
done
##################################################################
# cat Dockerfile
######################################################
FROM centos:centos7.5.1804
COPY clean_log.sh /
RUN groupadd -g 2020 test && \
useradd -u 2020 -g test test && \
chown test:test /clean_log.sh
USER test
CMD ["sh","/clean_log.sh"]
######################################################
参考
Shell脚本中让进程休眠的方法
https://www.jb51.net/article/57198.htm
ELK定时删除30天前日志
https://blog.csdn.net/weixin_34357928/article/details/89617286
Docker为什么刚运行就退出了
http://viabugs.com/2017/01/12/2017/docker-just-run-away
Docker容器一起动就退出的解决方案
https://blog.51cto.com/7603402/2304133
Gracefully Stopping Docker Containers
http://coinfaces.me/posts/gracefully-stop-docker-init-bash-script