獲取wiki某網頁信息shell即獲取wiki子目錄信息-shell
#!/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#<p>\|<br />#\n#g‘|sed ‘s# \|</p>\|"\|style=\color##g‘|sed ‘/^$/d‘ > towerContent.txt
##對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
獲取wiki某網頁信息shell即獲取wiki子目錄信息-shell