<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[[实践OK]shell批量查询URL返回状态码]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Php/Js/Shell/Go]]></category>
<pubDate>Mon, 16 Apr 2018 06:40:58 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	背景：个人博客里的友情链接发现好多链接都404了，要么是域名注册到期没有续费，要么搬家了，根本连接不过去了，影响页面加载速度怎么能快速清理掉？PHP版本的，只获取Header头，不获取Body内容的：http://jackxiang.com/post/6818/ ，尽管PHP比较能写，但是没有Shell更快实现作下简单一行处理。<br/>一）Linux下的一句话脚本：<br/><textarea name="code" class="php" rows="15" cols="100">
#cat 1.txt&#124;while read line;do curl -I -m 10 -o /dev/null -s -w %&#123;http_code&#125; $line &amp;&amp; echo $line;done
404http://man.chinaunix.net/develop/c&amp;amp;c++/linux_c/default.htm
404http://man.chinaunix.net/develop/c&amp;amp;c++/c/c.htm#_Toc520633993
000000000200http://www.cnblogs.com/meil
200http://www.gamutsoft.com/expert/list.aspx?nodeid=207
200http://you.video.sina.com.cn/v/mv/index.html
000000200http://blog.sina.com.cn/s/blog_482611850100xpb1.html
000200http://blog.sina.com.cn/dev
200http://blog.sina.com.cn/kaifulee
301http://v35.blog.sina.com.cn/u/1223842820
200http://blog.sina.com.cn/u/1188223274
</textarea><br/>二）写成多行：<br/><textarea name="code" class="php" rows="15" cols="100">
for i in `cat url.txt`
do
STATUS_CODE=`curl -o /dev/null -s -w %&#123;http_code&#125; $i`&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
echo -e &quot;$i:&#92;t$STATUS_CODE&quot; &gt;&gt;状态码.txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
done
</textarea><br/>三）分割文件，子Shell处理，没实践，代码如下：<br/>觉得数据多了就别直接用bash和curl做，换其他并发和网络编程更方便的语言。<br/><textarea name="code" class="php" rows="15" cols="100">
#!/usr/bin/bash

# 设置并发数
number_of_process=129

# 设置输入文件
input_file=&quot;url.txt&quot;

# 处理一个文件的函数
loop_file() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;local input_file=$1
&nbsp;&nbsp;&nbsp;&nbsp;local output_file=$2

&nbsp;&nbsp;&nbsp;&nbsp;mapfile urls &lt; $input_file
&nbsp;&nbsp;&nbsp;&nbsp;for url in $&#123;urls[@]&#125; ; do
&nbsp;&nbsp;&nbsp;&nbsp;STATUS_CODE=`curl -I -o /dev/null -s -w %&#123;http_code&#125; $url`
&nbsp;&nbsp;&nbsp;&nbsp;echo -e &quot;$url:&#92;t$STATUS_CODE&quot; &gt;&gt; $output_file
&nbsp;&nbsp;&nbsp;&nbsp;done
&#125;

# 分割文件
total_line=$(wc -l $input_file &#124; awk &#039;&#123;print $1&#125;&#039;)
line_per_file=$((total_line/number_of_process))
split -l $line_per_file $input_file $&#123;input_file&#125;_sub

# 每个文件用一个子shell处理
for f in $&#123;input_file&#125;_sub*; do
&nbsp;&nbsp;&nbsp;&nbsp;eval &quot;coproc $f &#123; loop_file $f output-$f; &#125;&quot;
done

# 等待子全部子shell完成
for f in $&#123;input_file&#125;_sub*; do
&nbsp;&nbsp;&nbsp;&nbsp;pid=$f_PID
&nbsp;&nbsp;&nbsp;&nbsp;wait $&#123;!pid&#125;
done

# 合并结果，删除中间文件
for f in $&#123;input_file&#125;_sub* ; do
&nbsp;&nbsp;&nbsp;&nbsp;cat output-$f &gt;&gt; 状态码.txt &amp;&amp; rm $f output-$f
done
</textarea><br/><br/><br/>来自：http://www.dewen.net.cn/q/15394/%E5%A6%82%E4%BD%95%E5%8A%A0%E5%BF%ABshell%E6%89%B9%E9%87%8F%E8%8E%B7%E5%8F%96url%E7%8A%B6%E6%80%81%E7%A0%81%E7%9A%84%E9%80%9F%E5%BA%A6%EF%BC%9F<br/>https://jingyan.baidu.com/article/fdbd4277d59af8b89e3f4895.html<br/><br/>
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [实践OK]shell批量查询URL返回状态码]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>