用SHELL访问特定的URL
生活随笔
收集整理的這篇文章主要介紹了
用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 這個腳本寫的不好,希望大神們幫忙改進改進
本文轉自1594cqb 51CTO博客,原文鏈接:http://blog.51cto.com/wolfchen/1083286,如需轉載請自行聯系原作者
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 這個腳本寫的不好,希望大神們幫忙改進改進
本文轉自1594cqb 51CTO博客,原文鏈接:http://blog.51cto.com/wolfchen/1083286,如需轉載請自行聯系原作者
總結
以上是生活随笔為你收集整理的用SHELL访问特定的URL的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: .NET实现之(WebService数据
- 下一篇: 关于Exchange邮箱服务器角色故障排