一个伪linux粉丝的blog
  1. 首页
  2. Uncategorized
  3. 正文

A simple shell script

2020年05月17日 202点热度 0人点赞 0条评论

上周客户有一个小需求,对某产品中的数据要求二次提炼,问了研发,没有提供api,目前没空搞,但是dashboard上已经有部分数据了,想想自己二次整理或许也能出结果,于是有了这个简单的shell脚本,为啥写这篇,因为用到了2个新的命令,有新收获,所以记录下。

代码不全,这里挑重点介绍python3 -mjson.tool和sed、以及tee命令就是这次的收获,处理查询的json文本,然后整理为所需的格式。
方法自然是curl,通过web界面获得bash命令后,自己开始琢磨


#开始时间
BeginTime=$(date -d "-1 week" +%Y-%m-%d) 

#结束时间
EndTime=$(date +%Y-%m-%d)

#这部分是查询top5,实际只需要top3,也就是最后size=3即可
curl '${QUERY_HOST}/query-server/v1/dashboard/top-calls?begin=${BeginTime}T00:00:01.001Z&end=${EndTime}T08:00:00.000Z&size=5' --compressed -o /tmp/top5.txt

根据环境情况,python2或python3 ,调用-mjson.tool工具,随后用sed处理所需的3段
#Forumal tenant top5 to top3
#Maybe neet python2 replace python3 根据环境情况,python2或python3 ,调用-mjson.tool工具,随后用sed处理所需的3段
cat /tmp/top5.txt|python3 -mjson.tool|sed -n '3,4p' >> /tmp/top3.txt
cat /tmp/top5.txt|python3 -mjson.tool|sed -n '9,10p' >> /tmp/top3.txt
cat /tmp/top5.txt|python3 -mjson.tool|sed -n '15,16p' >> /tmp/top3.txt

#Prepare for mail step1/3
echo 'The top 3 is here check now:)\n'| cat - /tmp/top3.txt | tee /tmp/top3.txt

#Get tenant SERVICE number

curl '${QUERY_HOST}/sw-query-service/dashboard/global-brief' -H 'Referer: ${QUERY_HOST}/dashboard' --compressed -o /tmp/total.txt

老规矩,整理好的临时文件通过mail发送给自己
mail -s "tenant stat is here" < /tmp/total-mail.txt [email protected]
还有一个重点其实是如何通过已知账号密码,通过token方式curl查询,研究了一下,比较复杂,当前仅理论实现,没测试。

Related posts:

  1. my first shell script
  2. Batch script delete printers
  3. how to get a free hax.tor.hu shell account
  4. batch-script-add-network-printer
标签: mjson.tool
最后更新:2020年05月13日

WanJie

正经人谁写博客啊?你写博客吗?写出来的那能叫博客?

点赞
< 上一篇
下一篇 >

文章评论

取消回复

分类目录
  • network
  • Uncategorized
  • unix/linux
  • 业界资讯
  • 公司杂事
  • 数码影像
  • 美剧
  • 美图共赏
  • 英语学习

COPYRIGHT © 2008-2021 一个伪linux粉丝的blog. ALL RIGHTS RESERVED.

THEME KRATOS MADE BY VTROIS