<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>旌旗博客 &#187; linux</title>
	<atom:link href="http://rocky.kingtch.com/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://rocky.kingtch.com</link>
	<description></description>
	<lastBuildDate>Tue, 14 Feb 2012 12:39:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>自动阻止SYN、DoS攻击</title>
		<link>http://rocky.kingtch.com/2008/07/23/%e8%87%aa%e5%8a%a8%e9%98%bb%e6%ad%a2syn%e3%80%81dos%e6%94%bb%e5%87%bb/</link>
		<comments>http://rocky.kingtch.com/2008/07/23/%e8%87%aa%e5%8a%a8%e9%98%bb%e6%ad%a2syn%e3%80%81dos%e6%94%bb%e5%87%bb/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 05:51:05 +0000</pubDate>
		<dc:creator>rocky</dc:creator>
				<category><![CDATA[I.T.]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.kingtch.com/2008/07/23/90/%e8%87%aa%e5%8a%a8%e9%98%bb%e6%ad%a2syn%e3%80%81dos%e6%94%bb%e5%87%bb.html</guid>
		<description><![CDATA[除了告警敦促人工处理SYN、DoS攻击，可以将嫌疑犯先抓起来再说： netstat -na &#124; grep :80 &#124;awk '{print $5}'&#124;awk -F '::ffff:' '{print $2}' &#124; grep ':' &#124; awk -F: '{print $1}' &#124; sort &#124; uniq -c &#124; sort -r &#124; awk -F' ' '{if ($1 &#62; 50) print $2}' &#124; sed 's/^.*$/iptables -I RH-Firewall-1-INPUT 1 -p tcp -m tcp -s &#38; --dport 80 --syn -j [...]]]></description>
			<content:encoded><![CDATA[<p>除了告警敦促人工处理SYN、DoS攻击，可以将嫌疑犯先抓起来再说：</p>
<pre>netstat -na | grep :80 |awk '{print $5}'|awk -F '::ffff:' '{print $2}' | grep ':' | awk -F: '{print $1}' | sort | uniq -c | sort -r | awk -F' ' '{if ($1 &gt; 50) print $2}' | sed 's/^.*$/iptables -I RH-Firewall-1-INPUT 1 -p tcp -m tcp -s &amp; --dport 80 --syn -j REJECT/' | sh</pre>
<p>该脚本基于的基础是认为从一个IP过来的连接数过大（超过50个），则该IP可能在进行攻击。实际上可能误杀掉一些只能通过代理服务器访问的大公司用户，或者某些有点贪心的网络爬虫。可以在脚本中加入一些白名单以防止误杀，如：</p>
<pre>netstat -na | grep :80 |awk '{print $5}'|awk -F '::ffff:' '{print $2}' | grep ':' | awk -F: '{print $1}' | sort | uniq -c | sort -r | awk -F' ' '{if ($1 &gt; 50) print $2}' | grep -v xxx.xxx.xxx.xxx | sed 's/^.*$/iptables -I RH-Firewall-1-INPUT 1 -p tcp -m tcp -s &amp; --dport 80 --syn -j REJECT/' | sh</pre>
<p><span style="text-decoration: underline"><a href="http://4thpeg.com/romads/post.php?p=9-4603"></a><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://rocky.kingtch.com/2008/07/23/%e8%87%aa%e5%8a%a8%e9%98%bb%e6%ad%a2syn%e3%80%81dos%e6%94%bb%e5%87%bb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>自动短信提醒进行服务器状态告警</title>
		<link>http://rocky.kingtch.com/2008/05/16/%e8%87%aa%e5%8a%a8%e7%9f%ad%e4%bf%a1%e6%8f%90%e9%86%92%e8%bf%9b%e8%a1%8c%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%8a%b6%e6%80%81%e5%91%8a%e8%ad%a6/</link>
		<comments>http://rocky.kingtch.com/2008/05/16/%e8%87%aa%e5%8a%a8%e7%9f%ad%e4%bf%a1%e6%8f%90%e9%86%92%e8%bf%9b%e8%a1%8c%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%8a%b6%e6%80%81%e5%91%8a%e8%ad%a6/#comments</comments>
		<pubDate>Fri, 16 May 2008 08:22:33 +0000</pubDate>
		<dc:creator>rocky</dc:creator>
				<category><![CDATA[I.T.]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.kingtch.com/2008/05/16/89/%e8%87%aa%e5%8a%a8%e7%9f%ad%e4%bf%a1%e6%8f%90%e9%86%92%e8%bf%9b%e8%a1%8c%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%8a%b6%e6%80%81%e5%91%8a%e8%ad%a6.html</guid>
		<description><![CDATA[定时启动的脚本： df &#124; grep “/var” &#124; awk &#8216;{ print $5 }&#8217; &#124; awk -F”%” &#8216;{print $1}&#8217; &#124; awk &#8216;{ if ($1 &#62; 90){print “alert.sh \”139xxxxxxxx\” \”insufficient disk space on /var. “,$1,”\”"} }&#8217; &#124; csh ps -ef &#124; grep httpd &#124; grep -v cronolog &#124; grep -v grep &#124; grep -v root &#124; wc -l &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>定时启动的脚本：</p>
<p>df | grep “/var” | awk &#8216;{ print $5 }&#8217; | awk -F”%” &#8216;{print $1}&#8217; | awk &#8216;{ if ($1 &gt; 90){print “alert.sh \”139xxxxxxxx\” \”insufficient disk space on /var. “,$1,”\”"} }&#8217; | csh<br />
ps -ef | grep httpd | grep -v cronolog | grep -v grep | grep -v root | wc -l | awk &#8216;{ if ($1 &gt; 3000){print “alert.sh \”139xxxxxxxx\” \”apache process “, $1,”\”"} }&#8217; | csh<br />
echo &#8216;show processlist&#8217; | mysql | grep -v Id | grep -v processlist | wc -l | awk &#8216;{ if ($1 &gt; 3000){print “alert.sh \”139xxxxxxxx\” \”mysql process “, $1,”\”"} }&#8217; | csh</p>
<p>alert.sh 脚本:</p>
<p>echo $2<br />
echo -e “From:monitor&lt;&gt;\nReply-to:support &lt;support.labs@etentec.com&gt;\nSubject:$2\n\n$2\n.” | /usr/sbin/sendmail $1@139.com</p>
]]></content:encoded>
			<wfw:commentRss>http://rocky.kingtch.com/2008/05/16/%e8%87%aa%e5%8a%a8%e7%9f%ad%e4%bf%a1%e6%8f%90%e9%86%92%e8%bf%9b%e8%a1%8c%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%8a%b6%e6%80%81%e5%91%8a%e8%ad%a6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>一个监视服务器状态的shell脚本</title>
		<link>http://rocky.kingtch.com/2008/05/16/%e4%b8%80%e4%b8%aa%e7%9b%91%e8%a7%86%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%8a%b6%e6%80%81%e7%9a%84shell%e8%84%9a%e6%9c%ac/</link>
		<comments>http://rocky.kingtch.com/2008/05/16/%e4%b8%80%e4%b8%aa%e7%9b%91%e8%a7%86%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%8a%b6%e6%80%81%e7%9a%84shell%e8%84%9a%e6%9c%ac/#comments</comments>
		<pubDate>Fri, 16 May 2008 06:03:47 +0000</pubDate>
		<dc:creator>rocky</dc:creator>
				<category><![CDATA[I.T.]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.kingtch.com/2008/05/16/88/%e4%b8%80%e4%b8%aa%e7%9b%91%e8%a7%86%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%8a%b6%e6%80%81%e7%9a%84shell%e8%84%9a%e6%9c%ac.html</guid>
		<description><![CDATA[#! /bin/bash for1do&#160;&#160;&#160; clear&#160;&#160;&#160; date&#160;&#160;&#160; echo -n &#8216;httpd process:&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216;;ps -ef &#124; grep httpd &#124; grep -v cronolog &#124; grep -v grep &#124; grep -v root &#124; wc -l&#160;&#160;&#160; echo -n &#8216;http connection:&#160;&#160; &#8216;;netstat -an &#124; grep :80 &#124; grep ESTABLISHED &#124; wc -l&#160;&#160;&#160; echo -n &#8216;mysql process:&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216;;echo &#8216;show processlist&#8217; &#124; mysql &#124; grep [...]]]></description>
			<content:encoded><![CDATA[<p>#! /bin/bash
<p>for<sup><a href="http://rocky.kingtch.com/2008/05/16/%e4%b8%80%e4%b8%aa%e7%9b%91%e8%a7%86%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%8a%b6%e6%80%81%e7%9a%84shell%e8%84%9a%e6%9c%ac/#footnote_0_85" id="identifier_0_85" class="footnote-link footnote-identifier-link" title=" ; ; ">1</a></sup><br />do<br />&nbsp;&nbsp;&nbsp; clear<br />&nbsp;&nbsp;&nbsp; date<br />&nbsp;&nbsp;&nbsp; echo -n &#8216;httpd process:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;;ps -ef | grep httpd | grep -v cronolog | grep -v grep | grep -v root | wc -l<br />&nbsp;&nbsp;&nbsp; echo -n &#8216;http connection:&nbsp;&nbsp; &#8216;;netstat -an | grep :80 | grep ESTABLISHED | wc -l<br />&nbsp;&nbsp;&nbsp; echo -n &#8216;mysql process:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;;echo &#8216;show processlist&#8217; | mysql | grep -v Id | grep -v processlist | wc -l<br />&nbsp;&nbsp;&nbsp; echo -n &#8216;mysql connection:&nbsp; &#8216;;netstat -an | grep 3306 | grep ESTABLISHED | wc -l<br />&nbsp;&nbsp;&nbsp; echo &#8216;tcp connection stats:&#8217;;netstat -n | awk &#8216;/^tcp/ {++S[$NF]} END {for(a in S) print “&nbsp;&nbsp; “,a, S[a]}&#8217;<br />&nbsp;&nbsp;&nbsp; echo &#8216;sorted ESTABLISHED connections: &#8216;;netstat -na|grep ESTABLISHED|awk &#8216;{print $5}&#8217;|awk -F: &#8216;{print $1}&#8217;|sort|uniq -c|sort -r +0n<br />&nbsp;&nbsp;&nbsp; echo &#8216;sorted SYN connections: &#8216;; netstat -na|grep SYN|awk &#8216;{print $5}&#8217;|awk -F: &#8216;{print $1}&#8217;|sort|uniq -c|sort -r +0n<br />&nbsp;&nbsp;&nbsp; sleep 5<br />done</p>
<ol class="footnotes"><li id="footnote_0_85" class="footnote"> ; ; </li></ol>]]></content:encoded>
			<wfw:commentRss>http://rocky.kingtch.com/2008/05/16/%e4%b8%80%e4%b8%aa%e7%9b%91%e8%a7%86%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%8a%b6%e6%80%81%e7%9a%84shell%e8%84%9a%e6%9c%ac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>配置自动登录的OpenSSH</title>
		<link>http://rocky.kingtch.com/2007/03/26/%e9%85%8d%e7%bd%ae%e8%87%aa%e5%8a%a8%e7%99%bb%e5%bd%95%e7%9a%84openssh/</link>
		<comments>http://rocky.kingtch.com/2007/03/26/%e9%85%8d%e7%bd%ae%e8%87%aa%e5%8a%a8%e7%99%bb%e5%bd%95%e7%9a%84openssh/#comments</comments>
		<pubDate>Mon, 26 Mar 2007 14:08:04 +0000</pubDate>
		<dc:creator>rocky</dc:creator>
				<category><![CDATA[I.T.]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://blog.kingtch.com/2007/03/26/76/%e9%85%8d%e7%bd%ae%e8%87%aa%e5%8a%a8%e7%99%bb%e5%bd%95%e7%9a%84openssh.html</guid>
		<description><![CDATA[&#160;&#160;&#160; &#160; 在不使用SecureCRT或者PuTTY的时候，用ssh登录远程服务器总是要输入密码，挺麻烦的。而且做系统管理，总是需要与自动化的命令行打交道，把密码明码写在脚本里实在不是一个合格的系统管理员做的事情。这儿有个解决办法： &#160;&#160;&#160;&#160;&#160; 1、在本机上创建密钥对： $ cd ~/.ssh$ ssh-keygen -t dsa&#160;&#160;&#160;根据提示输入密码，此密码与远程ssh密码无关。 &#160;&#160;&#160;&#160;&#160; 2、将公钥文件复制到远程服务器上： $ scp ~/.ssh/id_dsa.pub user@remote.host:pubkey.txt$ ssh user@remote.host$ mkdir ~/.ssh$ chmod 700 .ssh$ cat pubkey.txt &#62;&#62; ~/.ssh/authorized_keys$ rm ~/pubkey.txt$ chmod 600 ~/.ssh/*$ exit &#160;&#160;&#160;&#160;&#160; 3、测试远程服务器上的公钥： $ ssh user@remote.host&#160;&#160; 系统应该在这里提示要输入私钥密码，就是在ssh-keygen时创建的。$ exit &#160;&#160;&#160;&#160;&#160; 4、启动ssh-agent代理： $ eval `ssh-agent` &#160;&#160;&#160;&#160;&#160; 5、将私钥加到ssh-agent代理的缓存中去： $ ssh-add&#160;&#160;&#160; 又要输一遍私钥密码。 &#160;&#160;&#160;&#160;&#160; 6、测试一下： $ ssh [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;&nbsp;&nbsp; &nbsp; 在不使用SecureCRT或者PuTTY的时候，用ssh登录远程服务器总是要输入密码，挺麻烦的。而且做系统管理，总是需要与自动化的命令行打交道，把密码明码写在脚本里实在不是一个合格的系统管理员做的事情。这儿有个解决办法：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1、在本机上创建密钥对：</p>
<blockquote><p>$ cd ~/.ssh<br />$ ssh-keygen -t dsa<br /><em>&nbsp;&nbsp;&nbsp;根据提示输入密码，此密码与远程ssh密码无关。</em></p>
</blockquote>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2、将公钥文件复制到远程服务器上：</p>
<blockquote><p>$ scp ~/.ssh/id_dsa.pub <em>user@remote.host</em>:pubkey.txt<br />$ ssh <em>user@remote.host</em><br />$ mkdir ~/.ssh<br />$ chmod 700 .ssh<br />$ cat pubkey.txt &gt;&gt; ~/.ssh/authorized_keys<br />$ rm ~/pubkey.txt<br />$ chmod 600 ~/.ssh/*<br />$ exit</p>
</blockquote>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3、测试远程服务器上的公钥：</p>
<blockquote><p>$ ssh <em>user@remote.host<br />&nbsp;&nbsp; 系统应该在这里提示要输入私钥密码，就是在ssh-keygen时创建的。</em><br />$ exit</p>
</blockquote>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4、启动ssh-agent代理：</p>
<blockquote><p>$ eval `ssh-agent`</p>
</blockquote>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5、将私钥加到ssh-agent代理的缓存中去：</p>
<blockquote><p>$ ssh-add<br /><em>&nbsp;&nbsp;&nbsp; 又要输一遍私钥密码。</em></p>
</blockquote>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6、测试一下：</p>
<blockquote><p>$ ssh <em>user@remote.host</em><br />$ exit</p>
</blockquote>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7、因为自动登录的实现是由ssh-agent保存了登录信息实现的，因而在使用之前需要启动ssh-agent。自动启动ssh-agent代理：<a href="http://www.mtu.net/~engstrom/downloads/sssha">下载sssha脚本</a>，并放到~/.ssh/目录下，并在<tt>~/.bashrc</tt>文件中加入：</p>
<blockquote><p># setup ssh-agent, if appropriate<br />if [ -f "$HOME/.ssh/sssha" ]; then<br />&nbsp;&nbsp; source $HOME/.ssh/sssha<br />fi </p>
</blockquote>
<p>&nbsp;</p>
<p>本文参考<a href="http://www.mtu.net/~engstrom/ssh-agent.php">http://www.mtu.net/~engstrom/ssh-agent.php</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://rocky.kingtch.com/2007/03/26/%e9%85%8d%e7%bd%ae%e8%87%aa%e5%8a%a8%e7%99%bb%e5%bd%95%e7%9a%84openssh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>系统监控使用短信进行通知</title>
		<link>http://rocky.kingtch.com/2007/02/09/%e7%b3%bb%e7%bb%9f%e7%9b%91%e6%8e%a7%e4%bd%bf%e7%94%a8%e7%9f%ad%e4%bf%a1%e8%bf%9b%e8%a1%8c%e9%80%9a%e7%9f%a5/</link>
		<comments>http://rocky.kingtch.com/2007/02/09/%e7%b3%bb%e7%bb%9f%e7%9b%91%e6%8e%a7%e4%bd%bf%e7%94%a8%e7%9f%ad%e4%bf%a1%e8%bf%9b%e8%a1%8c%e9%80%9a%e7%9f%a5/#comments</comments>
		<pubDate>Fri, 09 Feb 2007 10:11:45 +0000</pubDate>
		<dc:creator>rocky</dc:creator>
				<category><![CDATA[I.T.]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://blog.kingtch.com/2007/02/09/60/%e7%b3%bb%e7%bb%9f%e7%9b%91%e6%8e%a7%e4%bd%bf%e7%94%a8%e7%9f%ad%e4%bf%a1%e8%bf%9b%e8%a1%8c%e9%80%9a%e7%9f%a5.html</guid>
		<description><![CDATA[code.screen, div.codescreen{ font-family: monospace; font-size: 1em; display: block; padding: 10px; border: 1px solid #bbb; background-color: #eee; color: #000; overflow: auto; border-radius: 2.5px; -moz-border-radius: 2.5px; margin: 0.5em 2em; } 1、发送短信： &#160;&#160;&#160;&#160;&#160;&#160;&#160;原来我是利用bj1860的邮箱的短信通知进行发短信，调用sendmail发送邮件就可以了。这个是要一条1毛钱的，现在公司有了移动的信息机，自然要好好利用了。只是信息机不是托管在IDC，也没有固定IP。没关系，劳动人民的力量是无穷的。 &#160;&#160;&#160;&#160;&#160;&#160; 1.1 我们先来做个动态dns。外面有些做DDNS服务的，但是也是要钱的。穷人有穷人的活法：&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 在信息机上做个计划任务，每10分钟执行一次这个批处理： d:\\cygwin\\bin\\wget -O ip.txt http://穷人的服务器/ddns/registerip.php &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 穷人的服务器上有个registerip.php： &#60;?php&#160;&#160;&#160;&#160; &#160;&#160;&#160;echo $_SERVER["REMOTE_ADDR"]; &#160;&#160;&#160;$handle = fopen ("ip.txt","w"); &#160;&#160;&#160;fwrite($handle,$_SERVER["REMOTE_ADDR"]); &#160;&#160;&#160;fclose ($handle);&#160; ?&#62; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 这样就在服务器上生成了一个记录了信息机网关IP的文件http://穷人的服务器/ddns/ip.txt。在服务器上要想访问信息机，还需要在信息机的网关的上做端口映射才行。&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160; 1.2 [...]]]></description>
			<content:encoded><![CDATA[<p>code.screen, div.codescreen{<br />
	font-family: monospace;<br />
	font-size: 1em;<br />
	display: block;<br />
	padding: 10px;<br />
	border: 1px solid #bbb;<br />
	background-color: #eee;<br />
	color: #000;<br />
	overflow: auto;<br />
	border-radius: 2.5px;<br />
	-moz-border-radius: 2.5px;<br />
	margin: 0.5em 2em;<br />
}</p>
<p>1、发送短信：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;原来我是利用bj1860的邮箱的短信通知进行发短信，调用sendmail发送邮件就可以了。这个是要一条1毛钱的，现在公司有了移动的信息机，自然要好好利用了。只是信息机不是托管在IDC，也没有固定IP。没关系，劳动人民的力量是无穷的。<img height="311" src="/files/uploads/2007/02/windowslivewriterf08ee9dc44c1-85e6monitor8.png" width="493" border="0">  </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.1 我们先来做个动态dns。外面有些做DDNS服务的，但是也是要钱的。穷人有穷人的活法：<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在信息机上做个计划任务，每10分钟执行一次这个批处理：</p>
</p>
<div class="codescreen">
<pre>d:\\cygwin\\bin\\wget -O ip.txt http://穷人的服务器/ddns/registerip.php</pre>
</div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 穷人的服务器上有个registerip.php：</p>
</p>
<div class="codescreen">
<pre>&lt;?php&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;echo $_SERVER["REMOTE_ADDR"];</pre>
<pre>
&nbsp;&nbsp;&nbsp;$handle = fopen ("ip.txt","w");
&nbsp;&nbsp;&nbsp;fwrite($handle,$_SERVER["REMOTE_ADDR"]);
&nbsp;&nbsp;&nbsp;fclose ($handle);&nbsp;
?&gt; </pre>
</p>
</div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这样就在服务器上生成了一个记录了信息机网关IP的文件http://穷人的服务器/ddns/ip.txt。在服务器上要想访问信息机，还需要在信息机的网关的上做端口映射才行。&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.2 在服务器上做个shell程序以方便的调用信息机上的发送短信接口：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 信息机上的发送短信接口为：http://信息机IP/sendSMS.php?phoneNumber=手机号&amp;content=短信内容。于是向单个手机号发送短信的shell程序sendsms.sh：</p>
<div class="codescreen">
<pre>

#!/bin/bash
declare -a smscontent=`echo $2 | sed -e "s/\ /+/g"`&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #URL中的参数里用+代替空格
`wget -q -O - http://穷人的服务器/ddns/ip.txt | sed -e "s/^/wget -q -O - http:\/\//g" | sed -e "s/$/\/sendSMS.jsp?phoneNumber=$1\&amp;content=$smscontent/g" | sed -e "s/\&amp;/\\\&amp;/g" `&nbsp; #从ip.txt取得IP地址，然后再前面加上"wget -q -O - http://"，在后面加上"\sendSMS.jsp?phoneNumber=$1\&amp;content=$smscontent"，再执行这条命令
</pre>
</div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 我们有多个人想得到通知，简单，再做个多发送的shell程序sendsms2.sh：</p>
<div class="codescreen">
<pre>

#!/bin/bash
echo $1 | awk -F";" '{for (i=NF;i&gt;0;--i) print "/home/rocky/sendsms.sh ",$i," "}' | sed -e "s/$/$2;/g" | csh
</pre>
</div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这样向多个手机号发送短信就这样写就行了：</p>
<div class="codescreen">
<pre>

sendsms2.sh "13910920000;13911060000" "短信内容"
</pre>
</div>
<p>&nbsp;</p>
<p>2、定期监控：</p>
<p>&nbsp;&nbsp;&nbsp; 1.1 监控磁盘空间：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 监控如果/var空间使用率超过85%则发送告警，使用crontab -e增加一条，每天9点15分检查：</p>
<div class="codescreen">
<pre>

15 09 * * * df | grep "/var" | awk '{ print $5 }' | awk -F"\%" '{print $1}' | awk '{ if ($1 &gt; 85){print "/usr/local/bin/sendsms2.sh \"13910920000;13911060000\" \"insufficient+disk+space+on+server\" "} }' | csh
</pre>
</div>
<p>&nbsp;&nbsp;&nbsp; 1.1 监控oracle连接数如果超过100则告警，9点到23点之间每半小时检查一次：</p>
</p>
<div class="codescreen">
<pre>*/30 9-23 * * * ps -ef | grep oracle | wc -l | awk '{ if ($1 &gt; 100){print "/usr/local/bin/sendsms2.sh \"13910920000;13911060000\" \"too many oracle connections\" "} }' | csh</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://rocky.kingtch.com/2007/02/09/%e7%b3%bb%e7%bb%9f%e7%9b%91%e6%8e%a7%e4%bd%bf%e7%94%a8%e7%9f%ad%e4%bf%a1%e8%bf%9b%e8%a1%8c%e9%80%9a%e7%9f%a5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&quot;Add Hardware&quot; on Redhat Linux</title>
		<link>http://rocky.kingtch.com/2007/01/26/add-hardware-on-redhat-linux/</link>
		<comments>http://rocky.kingtch.com/2007/01/26/add-hardware-on-redhat-linux/#comments</comments>
		<pubDate>Fri, 26 Jan 2007 03:03:06 +0000</pubDate>
		<dc:creator>rocky</dc:creator>
				<category><![CDATA[I.T.]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://rocky.blog.kingtch.com/2007/01/26/30/add-hardware-on-redhat-linux.html</guid>
		<description><![CDATA[During redhat is booting, system will detect new hardwares automatically.&#160;If you choose “Keep configuration” or&#160; “Do nothing”, system&#160;may not run correctly. Don&#8217;t regret,&#160;run “/usr/sbin/kudzu” under terminal, new hardwares and removed hardwares will be detected again, then you will have another chance to make a better&#160;decision.]]></description>
			<content:encoded><![CDATA[<p>During redhat is booting, system will detect new hardwares automatically.&nbsp;If you choose “Keep configuration” or&nbsp; “Do nothing”, system&nbsp;may not run correctly. Don&#8217;t regret,&nbsp;run “/usr/sbin/kudzu” under terminal, new hardwares and removed hardwares will be detected again, then you will have another chance to make a better&nbsp;decision.</p>
]]></content:encoded>
			<wfw:commentRss>http://rocky.kingtch.com/2007/01/26/add-hardware-on-redhat-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>windows环境中的linux环境 —— cygwin</title>
		<link>http://rocky.kingtch.com/2007/01/22/windows%e7%8e%af%e5%a2%83%e4%b8%ad%e7%9a%84linux%e7%8e%af%e5%a2%83-%e2%80%94%e2%80%94-cygwin/</link>
		<comments>http://rocky.kingtch.com/2007/01/22/windows%e7%8e%af%e5%a2%83%e4%b8%ad%e7%9a%84linux%e7%8e%af%e5%a2%83-%e2%80%94%e2%80%94-cygwin/#comments</comments>
		<pubDate>Mon, 22 Jan 2007 05:52:46 +0000</pubDate>
		<dc:creator>rocky</dc:creator>
				<category><![CDATA[I.T.]]></category>
		<category><![CDATA[cygwin]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://blog.kingtch.com/2007/01/22/22/windows%e7%8e%af%e5%a2%83%e4%b8%ad%e7%9a%84linux%e7%8e%af%e5%a2%83-%e2%80%94%e2%80%94-cygwin.html</guid>
		<description><![CDATA[第一次接触cygwin（http://cygwin.com/）已经是5年前了。windows的优点就是：傻瓜式，在windows下拥有一个linux环境还是很酷的。譬如查找文件内容，习惯了用grep的会很讨厌用windows的explorer自带的搜索功能，太弱智了，而且bug不老少的，记得有次我好心好意地写邮件给M$说明bug情况，他们居然回邮件啥都不说就问我要客户号，晕啊，扯远了…… cygwin提供了一个叫做cygwin1.dll的dll，这个dll提供了linux API模拟层。很多linux上常用的工具都能基于cygwin上运行，譬如make、gcc等等，甚至gnome。 远程linux上运行一些程序譬如oracle的安装程序需要图形界面时，用cygwin就能轻松搞定。 先在本地启动X服务器： $ XWin.exe -ac -multiwindow &#38; 再在远程linux上设置环境变量： $ export DISPLAY=:0.0 之后就可在远程linux上运行程序，在本地的窗口中操作程序的图形界面了。 如果想操作远程linux的桌面： 本地运行： $ XWin.exe -ac &#38; 再远程linux上设置好DISPLAY之后，运行 $ gnome-wm &#38; # 这是窗口管理器 $ gnome-panel &#38; # 这是gnome的任务条之类的管理程序]]></description>
			<content:encoded><![CDATA[<p>第一次接触cygwin（http://cygwin.com/）已经是5年前了。windows的优点就是：傻瓜式，在windows下拥有一个linux环境还是很酷的。譬如查找文件内容，习惯了用grep的会很讨厌用windows的explorer自带的搜索功能，太弱智了，而且bug不老少的，记得有次我好心好意地写邮件给M$说明bug情况，他们居然回邮件啥都不说就问我要客户号，晕啊，扯远了……</p>
<p>cygwin提供了一个叫做cygwin1.dll的dll，这个dll提供了linux API模拟层。很多linux上常用的工具都能基于cygwin上运行，譬如make、gcc等等，甚至gnome。</p>
<p>远程linux上运行一些程序譬如oracle的安装程序需要图形界面时，用cygwin就能轻松搞定。</p>
<p>先在本地启动X服务器：<br />
$ XWin.exe -ac -multiwindow &amp;<br />
再在远程linux上设置环境变量：<br />
$ export DISPLAY=:0.0<br />
之后就可在远程linux上运行程序，在本地的窗口中操作程序的图形界面了。</p>
<p>如果想操作远程linux的桌面：<br />
本地运行：<br />
$ XWin.exe -ac &amp;<br />
再远程linux上设置好DISPLAY之后，运行<br />
$ gnome-wm &amp;                       # 这是窗口管理器<br />
$ gnome-panel &amp;                    # 这是gnome的任务条之类的管理程序</p>
]]></content:encoded>
			<wfw:commentRss>http://rocky.kingtch.com/2007/01/22/windows%e7%8e%af%e5%a2%83%e4%b8%ad%e7%9a%84linux%e7%8e%af%e5%a2%83-%e2%80%94%e2%80%94-cygwin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

