教程集 www.jiaochengji.com
教程集 >  脚本编程  >  shell  >  正文 shell脚本中使用curl下载更新号段表

shell脚本中使用curl下载更新号段表

发布时间:2014-12-07   编辑:jiaochengji.com
分享一例shell脚本,实现使用curl来下载更新号码段表的功能,有需要的朋友参考学习下,相信对你一定会有帮助的。

本节内容:
一段使用curl下载与更新号段表的shell脚本代码。

在运维中,经常会遇到手机号段没有时实更新造成的问题。

本例culrl的地址在此不便给出,网上查询号段的都可以,地址不同后面sed截取也要做相应更改。

系统需要带有curl如果没有请自行安装。
本例对已有号段进行判断,即只解析新增号段。本例解析对像为联通号段。
增加了10的倍数sleep 2,防止频繁提交,具体看需要调整。
第一个FOR 大号段会并发提交,提高处理效率。

附,代码
 

复制代码 代码示例:
#!/bin/bash
# File Name: test.sh
# site: www.jiaochengji.com
# Created Time: 2013年08月08日 星期四 22时59分13秒
# curl 解析联通号段,大号段后台并发执行。
#--------------------
#for i in 130;do
for i in 130 131 132 155 156 185 186;do
{
    for j in {0000..9999};do
        code=$i$j
        #存在codesect里则不提交curl
        code_re=`sed -n  "/$code/p" codesect`
        if [ -z "$code_re" ];then
            #10的倍数休息2秒
            if [ $[$code%10] -ne 0 ];then
                curl_re=`curl -s wap.XXXX.com/sim_search.asp?mobile=$code|sed -n '15p'|sed 's#<br/>##g'`
                echo $code $curl_re
                echo $code $curl_re >>defcodesect
            else
                curl_re=`curl -s wap.XXXX.com/sim_search.asp?mobile=$code|sed -n '15p'|sed 's#<br/>##g'`
                echo $code $curl_re
                echo $code $curl_re >>defcodesect
                echo "sleep 2....."
                sleep 2
            fi
        else
            echo $code >>exist_code
            echo "${code} existing,ignore!!"
        fi
    done
}&
done
    wait

您可能感兴趣的文章:
shell脚本中使用curl下载更新号段表
shell脚本使用curl批量解析号码归属地
使用curl获取网站的http的状态码
解决PHP中Web程序中shell_exec()执行Shell脚本不成功问题
linux使用curl监控网页的shell脚本
php如何使用curl?(用法介绍)
执行php脚本的几种办法
php curl发送请求详细教程
shell脚本下载网页图片
inux shell初级入门教程

[关闭]
~ ~