一个伪linux粉丝的blog

  1. 首页
  2. Uncategorized
  3. 正文

A simple shell script

17 5 月, 2020 878点热度 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
最后更新:13 5 月, 2020

wanjie

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

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

This site uses Akismet to reduce spam. Learn how your comment data is processed.

归档
分类
  • network / 332篇
  • Uncategorized / 116篇
  • unix/linux / 121篇
  • 业界资讯 / 38篇
  • 公司杂事 / 11篇
  • 数码影像 / 12篇
  • 美剧 / 3篇
  • 美图共赏 / 21篇
  • 英语学习 / 3篇
标签聚合
google-chrome VPS debian jira Google Voice Nginx k8s d90 dreamhost dreamhost空间 网站运营 浏览器 Google kernel nexus Ubuntu postgres docker deepseek 邮件归档 天翼live openssl ldap wget ssh gitlab 虚拟主机 泰国 squid kubectl

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

Theme Kratos Made By Seaton Jiang