#!/bin/bash
##################################################
##################################################
set -e
##需要参数
if [ $# -eq 0 ];then
echo "需要参数,例如下面命令"
echo "sh $0 -h"
exit 1
fi
##shell需要jq命令
#apt-get install -y jq 1>/dev/null 2>&1
##获取 wiki tower记录,下载到本地 towerCount.js ##############################################
wget -O towerCount.js "http://xxurl/wiki/page.json?pageid=xx" 2>/dev/null
##获取id、title、url,并显示在页面
cat towerCount.js |jq . |grep -E "id|title|url"
##获取tower内容,并写入到文件
cat towerCount.js |jq .data.content |sed 's#
\|
#\n#g'|sed 's# \|
##对tower内容,进行条件输出
while getopts "n:d:ah" arg
do
case $arg in
n)
head -n $OPTARG towerContent.txt
;;
d)
head -n1 towerContent.txt;cat towerContent.txt|grep $OPTARG
;;
a)
cat towerContent.txt
;;
h)
echo "sh $0 -n num(行数), 显示最近n天的记录 sh $0 -n 2"
echo "sh $0 -d date 显示这天的记录 example: sh $0 -d 2017-8-01"
echo "sh $0 -a 显示所有的记录 example: sh $0 -a"
echo "sh $0 -h 显示帮助 example: sh $0 -h"
;;
?)
echo "unkonw argument; sh $0 -n num(行数) or -d 2017-08-12 or -a"
;;
esac
done