shell调用webservice
今日为了向同事讲解shell,特地用其调用webservice获得返回信息,展现shell的妙用。此次本人再次领略到shell和linux的强大。shell的关键之处是curl、xpath的使用。webservice使用公共的地址:http://ws.webxml.com.cn/webservices/DomesticAirline.asmx/getDomesticAirlinesTime,代码如下:
// shell
#!/usr/bin/env bash
#程序目的:通过bash调用webservice获取航空信息
#程序版本:bash5.0
#程序编写:枫叶
#编写时间:2020年3月15日
#平台:Fedora31
str="----------航空信息查询----------"
echo -e "${str}\n"
function get_schedule()
{
flag=0
req_time=$(date "+%Y-%m-%d %H:%M:%S")
printf "${req_time} request...\n"
#####定义变量方式获得信息#####
start_city="桂林"
arrive_city="上海"
query_date="2020-3-18"
res=`curl -d "startCity=${start_city}&lastCity=${arrive_city}&theDate=${query_date}&userID=" http