一个伪linux粉丝的blog

  1. 首页
  2. Uncategorized
  3. 正文

A simple shell script

5月 17, 2020 491点热度 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查询,研究了一下,比较复杂,当前仅理论实现,没测试。

相关文章:

  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
最后更新:5月 13, 2020

wanjie

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

取消回复

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据。

归档
分类
  • network / 324篇
  • Uncategorized / 116篇
  • unix/linux / 114篇
  • 业界资讯 / 38篇
  • 公司杂事 / 11篇
  • 数码影像 / 12篇
  • 美剧 / 3篇
  • 美图共赏 / 20篇
  • 英语学习 / 3篇
标签聚合
kernel Ubuntu dreamhost空间 Google Adwords Linux 网通 debian brew Google dreamhost ldap nexus Android 网站运营 wget Google Voice d90 虚拟主机 邮件归档 k8s Nginx Opera Mini docker iMac jira 泰国 gitlab VPS 刷机 中国电信

COPYRIGHT © 2008-2022 wanjie.info. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang