<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Ops运维 | Mr`kang Blog｜小豆子]]></title> 
<link>https://www.cnmysql.com/index.php</link> 
<description><![CDATA[关注服务器运维技术、DB优化、Docker虚拟化、自动化运维、工作积累]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Ops运维 | Mr`kang Blog｜小豆子]]></copyright>
<item>
<link>https://www.cnmysql.com/post//</link>
<title><![CDATA[端口检测并报警]]></title> 
<author>kangyang &lt;kangyang315@qq.com&gt;</author>
<category><![CDATA[SHELL脚本]]></category>
<pubDate>Mon, 21 Jul 2014 08:41:40 +0000</pubDate> 
<guid>https://www.cnmysql.com/post//</guid> 
<description>
<![CDATA[ 
	<div class="code"><br/>#!/bin/bash<br/>#检测服务器端口是否开放，成功会返回0值显示ok，失败会返回1值显示fail&nbsp;&nbsp;<br/>PWD=`pwd`<br/>port=9888<br/>date=`date +&quot;%Y-%m-%d %H:%M:%S&quot;`<br/><br/><br/>Rsync_exec()&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expect -c &quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set timeout 600;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spawn rsync -rpogtvae &#92;&quot;ssh -p 1918&#92;&quot; root@114..11.11.11:/home/python-ssh/hostlist&nbsp;&nbsp;/home/soft<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expect &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#92;&quot;*yes/no*&#92;&quot; &#123;send &#92;&quot;yes&#92;r&#92;&quot;;exp_continue&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#92;&quot;*password*&#92;&quot; &#123;send &#92;&quot;xxxxx&#92;r&#92;&quot;;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expect eof;&quot;<br/>&#125;<br/>Rsync_exec<br/><br/><br/><br/>echo &quot;----------------------$date 以下游戏服9888端口没启动请检查！--------------------&quot; &gt;$PWD/port_closed_status<br/><br/>while read line<br/>do<br/>&nbsp;&nbsp;nc -w 40 -z $line $port &gt; /dev/null 2&gt;&amp;1 <br/>&nbsp;&nbsp;if &#91; $? -eq 0 &#93;; then<br/>&nbsp;&nbsp;echo &quot;$line--$port端口status: 开启!&quot;<br/>&nbsp;&nbsp;else<br/>&nbsp;&nbsp;echo &quot;$line--$port端口status: 关闭!&quot; <br/>&nbsp;&nbsp;echo &quot;$line--$port端口status: Closed&quot; &gt;&gt;$PWD/port_closed_status<br/>&nbsp;&nbsp;fi<br/> sleep 1;<br/>done&lt;$PWD/hostlist<br/><br/><br/>cat $PWD/port_closed_status<br/><br/><br/>#send mail<br/>closed=`cat $PWD/port_closed_status &#124; grep Closed`<br/>if &#91; &quot;$closed&quot; != &quot;&quot; &#93;<br/>then<br/>iconv -f utf-8 -t gb2312 $PWD/port_closed_status &#124; tee $PWD/port_closed_status.txt &gt; /dev/null<br/>mail -s &quot;Server Port Status &quot; xxxxxxx@qq.com &lt; $PWD/port_closed_status.txt -- -f monitor@t4game.com<br/>fi<br/></div>
]]>
</description>
</item><item>
<link>https://www.cnmysql.com/post//#blogcomment</link>
<title><![CDATA[[评论] 端口检测并报警]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://www.cnmysql.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>