用SHELL访问特定的URL
今天开发给了我一个需求,需要用shell访问特定的URL。需求如下:
开发给了4个URL例如:
http://www.chlinux.net/index/consortialevel?server=s$XX
http://www.chlinux.net/index/consortiafight?server=sXX
http://www.chlinux.net/index/rolefight?server=sXX
http://www.chlinux.net/index/rolelevel?server=sXX
XX需要到数据库中取值,取值后结合下面的4个网址用curl访问,然后取得返回值给开发。
我的思路是先到数据库取值保存到一个文件中,然后用AWK分割在用for循环来访问这些URL,脚本如下:
#!/bin/bash DATE=`date "+%Y%m%d"` LOG_FILE=/tmp/$DATE.curl.txt ERR_FILE=/tmp/$DATE.ERROR.txt SERVER_LIST=/tmp/$DATE.server.list.txt mysql typecho -uadmin -p123456 -sN -e "select * from typecho_relationships" >>$SERVER_LIST for i in `awk -F " " '{print $2}' $SERVER_LIST` do echo "http://www.chinux.net/index/consortialevel?server=s$i= `curl http://www.chinux.net/index/consortialevel?server=s$i`" >>$LOG_FILE echo "http://wwww.chinux.net/index/consortiafight?server=$i= `curl http://www.chinux.net/index/consortiafight?server=s$i`" >>$LOG_FILE echo "http://www.chinux.net/index/rolefight?server=s$i= `curl http://www.chinux.net/index/rolefight?server=s$i`" >>$LOG_FILE echo "http://www.chinux.net/index/rolelevel?server=s$i= `curl http://www.chinux.net/index/rolelevel?server=s$i`" >>$LOG_FILE done ERROR_LOG=`awk -F " " '{if($2==0) print $0, "\n"}' $LOG_FILE` echo $ERROR_LOG >>$ERR_FILE
这个脚本写的不好,希望大神们帮忙改进改进