通过shell脚本批处理es数据
#!/bin/sh
【按照指定的域名-website集合,遍历各个域名,处理url】
#指定待删除的变量集合
arr=(6.0)
cur="`date +%Y%m%d%H%M%S`"
res_file=${BASH_SOURCE}.${cur}.json.txt
log_file=${BASH_SOURCE}.${cur}.log
es_str=''
for v in ${arr[@]}
do
es_str='curl testIP:9200/my_index/my_doc//_search?pretty=true -d "{"_source": false,"query": {"match": {"website": "'$v'"}},"from": 1,"size": 9999}"'
echo $es_str
eval $es_str >> $res_file
done str_head='{"delete":{"_id":"'
str_foot='"}}' split_file_dir='/data/xiaole_chk_url/domain_iask/'
bulk_file=${split_file_dir}${BASH_SOURCE}.${cur}.json
#创建文件
echo '' > $bulk_file #单引号字符串的限制:
#单引号里的任何字符都会原样输出,单引号字符串中的变量是无效的;
#单引号字串中不能出现单引号(对单引号使用转义符后也不行)。
#双引号
#your_name='qinjx'
#str="Hello, I know your are \"$your_name\"! \n"
#双引号的优点:
#双引号里可以有变量
#双引号里可以出现转义字符 str_tag='"_id" : "' #读取文件,生成批处理文件
while read line
do
echo $line
# if [ $a = $line ]
# if test $a -eq $line
if [[ $line == *$str_tag* ]]
then
#查找目标字符串
#${string#substring}从变量$string的开头, 删除最短匹配$substring的子串 a=${line#'"_id" : "'}
#${string//substring/replacement}
#Shell字符串比较相等、不相等方法小结 - CSDN博客 https://blog.csdn.net/mr_leehy/article/details/76383091
#shell中if做比较 - 生活费 - 博客园 http://www.cnblogs.com/276815076/archive/2011/10/30/2229286.html
b=${a//'",'/''}
echo $b
echo ${str_head}${b}${str_foot} >> $bulk_file
else
echo bbb
fi
unset a
unset b
done<$res_file #{"delete":{"_id":website.com.cn/b/tpoNpaBlFx.html"}}
#{"delete":{"_id":website.com.cn/b/4W0xcTKZib.html"}}
#{"delete":{"_id":website.com.cn/b/5dptLwDEaD.html"}}
#{"delete":{"_id":website.com.cn/b/4OdzPUwb6X.html"}}
#{"delete":{"_id":website.com.cn/b/2baCMVRsAH.html"}}
#{"delete":{"_id":website.com.cn/b/2Nb6PnEt0T.html"}}
#{"delete":{"_id":website.com.cn/b/3GbeNhQvyP.html"}}
#{"delete":{"_id":website.com.cn/b/3z2wWJWhIf.html"}}
#{"delete":{"_id":website.com.cn/b/1id9c9K1MT.html"}}
#{"delete":{"_id":website.com.cn/b/2UYjsh1fcf.html"}}
#{"delete":{"_id":website.com.cn/b/66PtNs1vbt.html"}} #执行批处理文件es删除操作 curl -XPOST testIP:9200/my_index/my_doc//_bulk --data-binary @$bulk_file >> $log_file exit 0 #检查结果 【返回指定id的查询结果】
#curl 'testIP:9200/my_index/my_doc//_search?pretty=true' -d '
#{
#"query" : {
#"bool" : {
#"should" : [
#{ "match" : { "_id": "website.com.cn/b/KV4Lw3dAw1.html" } },
#{ "match" : { "_id": "website.com.cn/b/KI9t2kvSlT.html" } },
#{ "match" : { "_id": "website.com.cn/b/4Hdkz68Vox.html" } },
#{ "match" : { "_id": "bbs.py168.com/xinxi/25975882.html" } }
# ]
# }
#}
#}' 【检查日志】 #{"took":1980,"errors":false,"items":[{"delete":{"_index":"my_index","_type":"my_doc","_id":"website.com.cn/b/KzVLkQWh9b.html","_version":2,"_shards":{"total":2,"successful":2,"failed":0},"status":200,"found":true}},{"delete":{"_index":"my_index","_type":"my_doc","_id":"website.com.cn/b/Lc2SQpxEPP.html","_version":2,"_shards":{"total":2,"successful":2,"failed":0},"status":200,"found":true}},{"delete":{"_index":"my_index","_type":"my_doc","_id" #!/bin/sh 【
#穷举站点值,得到满足一定条件的rul
#可以在穷举循环中,再加一层穷举,得到满足一定条件的url全集
】 loop_step=1
loop_stop=5000
loop_period_start=0
loop_period_end=0
cur="`date +%Y%m%d%H%M%S`"
res_file=${BASH_SOURCE}.$cur.json.txt
log_file=${BASH_SOURCE}.$cur.log
es_str=''
for((i=0;i<$loop_stop;i++))
do
loop_period_start=$((i*loop_step))
loop_period_end=$((loop_period_start+loop_step))
echo $loop_period_start
echo $loop_period_end
echo $i
#查找域名 size为1;查找域名的子模式,比如是否存在/m/疑似手机站,则设为系统最大值9999 es_str='curl testIP:9200/my_index/my_doc//_search?pretty=true -d "{"query": {"match": {"website": "'${loop_period_start}'"}},"_source":true,"from":1,"size":9999}"' echo $es_str
#将执行结果写入结果文件
eval $es_str >> $res_file
done str_head='{"delete":{"_id":"'
str_foot='"}}' split_file_dir='/data/xiaole_chk_url/url_mobile/'
bulk_file=${split_file_dir}${BASH_SOURCE}.${cur}.json str_tag='"_id" : "'
str_tag_mobile='/m/' #读取文件,生成批处理文件
while read line
do
if [[ $line == *$str_tag* ]]
then
if [[ $line == *$str_tag_mobile* ]]
then
#查找目标字符串
a=${line#'"_id" : "'}
b=${a//'",'/''}
echo $line
echo ${str_head}${b}${str_foot} >> $bulk_file
else
echo 'filter_1'
fi
else
echo 'filter_o'
fi
done<$res_file #curl -XPOST testIP:9200/my_index/my_doc//_bulk --data-binary @$bulk_file >> $log_file exit 0
shell 文件读取 if else 分支 字符串查找 模糊匹配 字符串截取
es 批处理 批删除
通过shell脚本批处理es数据的更多相关文章
- shell编程系列24--shell操作数据库实战之利用shell脚本将文本数据导入到mysql中
shell编程系列24--shell操作数据库实战之利用shell脚本将文本数据导入到mysql中 利用shell脚本将文本数据导入到mysql中 需求1:处理文本中的数据,将文本中的数据插入到mys ...
- Shell脚本处理JSON数据工具jq
shell脚本如何方便地处理JSON格式的数据呢,这里介绍一个工具:jq 使用参数介绍:https://stedolan.github.io/jq/manual/ 官方教程简单翻译如下. 1.获取JS ...
- shell脚本中的数据传递方式
shell中支持的数据传递方式 主要有那么几种: 变量.管道.结果引用.重定向+文件.以及xargs. 变量方式: 1. 定义变量: 变量名=值 2. 使用变量: $变量名 管道方式: 统计当前文件夹 ...
- 案例:通过shell脚本实现mysql数据备份与清理
Shell是系统的用户界面,提供了用户与内核进行交互操作的一种接口.它接收用户输入的命令并把它送入内核去执行,实际上Shell是一个命令解释器,它解释由用户输入的命令并且把它们送到内核,不仅如此,Sh ...
- shell脚本处理二进制数据
正确处理二进制数据 正确处理二进制数据必须保证以下三个环节是二进制安全(Binary Safe)的: 从文件读取至内存: 处理数据过程中: 内存写入至文件. 那么二进制安全是什么?通俗来说就是不会特殊 ...
- shell脚本处理大数据系列之(一)方法小结
转自:http://longriver.me/?p=57 方法1: 单进程处理大规模的文件速度如(上million量级)比较慢,可以采用awk取模的方法,将文件分而治之,这样可以利用充分的利用多核CP ...
- Shell脚本实现用户数据导入
#输入:固定格式的用户数据user.sql #处理:循环读取user.sql中的每行(每行对应一条用户数据),依次调用curl命令将用户插入BearyChat #输出:执行结果输出到日志文件outlo ...
- linux下使用shell脚本批处理命令
1.新建脚本touch first.sh 2.写入命令vi first.sh #!/bin/bash #publish service and api echo "copy file&quo ...
- 使用shell脚本批处理控制大数据环境服务启动停止
三台集群机器: master 192.168.168.200 slave1 192.168.168.201 slave2 192.168.168.202 1.start-maste ...
随机推荐
- 开源敏捷测试管理& 开源BUG跟踪管理软件itest(爱测试) V3.3.0隆重发布
v3.3.0 下载地址 :itest下载 码云源码地址 https://gitee.com/itestwork/itest 开源中国 itest项目地址 https://www.oschina. ...
- ios打电话发短信接口
电话.短信是手机的基础功能,iOS中提供了接口,让我们调用.这篇文章简单的介绍一下iOS的打电话.发短信在程序中怎么调用. 1.打电话 [[UIApplication sharedApplicatio ...
- 关键字搜索高亮jQuery插件
// textSearch.js v1.0 文字,关键字的页面纯客户端搜索// 2010-06-23 修复多字母检索标签破碎的问题// 2010-06-29 修复页面注释显示的问题// 2013-05 ...
- for in,Object.keys()与for of的用法与区别
Array.prototype.sayLength=function(){ console.log(this.length); } let arr = ['a','b','c','d']; arr.n ...
- 「 HDU P4734 」 F(x)
# 题目大意 对于一个数 $x$,它的每一位数字分别是 $A_{n}A_{n-1}A_{n-2}\cdots A_{2}A_{1}$,定义其权重 $f(x)=\sum_{i=1}^{n}\left(A ...
- 数据库的ACID 简谈
一.事务 定义:所谓事务,它是一个操作序列,这些操作要么都执行,要么都不执行,它是一个不可分割的工作单位. 准备工作:为了说明事务的ACID原理,我们使用银行账户及资金管理的案例进行分析. 二.ACI ...
- Samba 学习笔记
这个网站不错.https://www.ibm.com/developerworks/cn/linux/l-lpic3-311-1/
- 1. 垃圾收集简介 - GC参考手册
说明: 在本文中, Garbage Collection 翻译为 “垃圾收集”, garbage collector 翻译为 “垃圾收集器”; 一般认为, 垃圾回收 和 垃圾收集 是同义词. Mino ...
- poj 3253 Fence Repair (优先队列,哈弗曼)
题目链接:http://poj.org/problem?id=3253 题意:给出n块木板的长度L1,L2...Ln,求在一块总长为这个木板和的大木板中如何切割出这n块木板花费最少,花费就是将木板切割 ...
- 将[object Object]转换成json对象
这两天在做中英文双版的文件,页面根据语言读取不同的内容.js模板用的是ejs json文件: "components":{ "pages":{ "ho ...