個(gè)人專題目錄
?
1. 用shll腳本讓測(cè)試環(huán)境自動(dòng)部署
#!/usr/bin/env bash
source /etc/profile
begin_time=`date "+%Y-%m-%d %H:%M:%S"`
echo 'begin_time:'${begin_time}
# 項(xiàng)目git路徑
project_path="/data/projects/demo"
# 切換到項(xiàng)目路徑
cd ${project_path}
# 獲取當(dāng)前項(xiàng)目的git commitId
git_commit_id_old=`git log | head -1 | awk -F ' ' '{print $2}'`
echo 'git_commit_id_old:'${git_commit_id_old}
# 拉取項(xiàng)目更新
git pull
# 獲取拉取后的項(xiàng)目的git commitId
git_commit_id_new=`git log | head -1 | awk -F ' ' '{print $2}'`
echo 'git_commit_id_new:'${git_commit_id_new}
# 判斷前后是否相等
if [[ ${git_commit_id_old} != ${git_commit_id_new} ]]
then
echo "demo自動(dòng)部署開(kāi)始"
sh /root/deploy.sh
echo "demo自動(dòng)部署結(jié)束"
else
echo "沒(méi)有變更,跳過(guò)自動(dòng)部署"
fi
end_time=`date "+%Y-%m-%d %H:%M:%S"`
echo 'end_time:'${end_time}
2. shell腳本去解析json數(shù)據(jù)
#!/bin/sh
# 淘寶接口,獲取IP接口
retVal=$(curl -s -X GET \
http://ip.taobao.com/service/getIpInfo.php?ip=63.223.108.42 \
-H 'cache-control: no-cache')
echo 'retVal: ' ${retVal}
# {"code":0,"data":{"ip":"63.223.108.42","country":"美國(guó)","area":"","region":"華盛頓","city":"西雅圖","county":"XX","isp":"電訊盈科","country_id":"US","area_id":"","region_id":"US_147","city_id":"US_1107","county_id":"xx","isp_id":"3000107"}}
echo '{"foo": 42, "bar": "less interesting data"}' | jq .foo
echo ${retVal} | jq .data.ip
country=$(echo ${retVal} | jq .data.country)
echo 'country: ' ${country}