shell 定时任务删除索引日志

2019-05-24  本文已影响0人  胖嘟嘟洒酒疯
  1. es按照日期新建索引
 index => "%{[index]}-%{+YYYY.MM.dd}"
  1. shell脚本定时删除三天前的索引

    crontab命令使用

    -u user:用来设定某个用户的crontab服务,例如,“-u ixdba”表示设定ixdba用户的crontab服务,此参数一般有root用户来运行。
    
    file:file是命令文件的名字,表示将file做为crontab的任务列表文件并载入crontab。如果在命令行中没有指定这个文件,crontab命令将接受标准输入(键盘)上键入的命令,并将它们载入crontab。
    
    -e:编辑某个用户的crontab文件内容。如果不指定用户,则表示编辑当前用户的crontab文件。
    
    -l:显示某个用户的crontab文件内容,如果不指定用户,则表示显示当前用户的crontab文件内容。
    
    -r:从/var/spool/cron目录中删除某个用户的crontab文件,如果不指定用户,则默认删除当前用户的crontab文件。
    
    -i:在删除用户的crontab文件时给确认提示。
    

    新建文件 cron

    SHELL=/bin/bash
    PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
    
    
    0 1 * * *  sh /home/refresh-elasticsearch.sh
    

    编写执行脚本refresh-elasticsearch.sh

    #!/bin/bash
    current=`date -d "-3 day" +"%Y.%m.%d"` 
    echo ${current} >> /home//sdout
    echo 'http://localhost:9200/index-'${current}'' >> /home/sdout
    
    curl -X DELETE 'http://localhost:9200/index-'${current}'' >> /home/sdout
    
    #curl -X DELETE 'http://localhost:9200/index' >> /home/sdout
    
上一篇 下一篇

猜你喜欢

热点阅读