<?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>浮山狼de博客 &#187; shell</title>
	<atom:link href="https://www.fushanlang.com/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fushanlang.com</link>
	<description>next station - 下一站，活在当下，且行且思</description>
	<lastBuildDate>Sat, 29 Nov 2014 15:14:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.5</generator>
	<item>
		<title>linux shell 交互yes or no</title>
		<link>https://www.fushanlang.com/linux-shell-jiao-hu-yes-or-no-2247/</link>
		<comments>https://www.fushanlang.com/linux-shell-jiao-hu-yes-or-no-2247/#comments</comments>
		<pubDate>Thu, 25 Oct 2012 07:46:04 +0000</pubDate>
		<dc:creator><![CDATA[fushanlang]]></dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.fushanlang.com/blog/?p=2247</guid>
		<description><![CDATA[<p>第一种方案:</p> while true; do read -p "Do you wish to install this program?" yn case $yn in [Yy]* ) make install; break;; [Nn]* ) exit;; * ) echo "Please answer yes or no.";; esac done <p>第二种方案:</p> echo "Do you wish to install this program?" select yn in "Yes" "No"; do case $yn in Yes <span style="color:#777"> . . . &#8594; Read More: <a href="https://www.fushanlang.com/linux-shell-jiao-hu-yes-or-no-2247/">linux shell 交互yes or no</a></span>]]></description>
				<content:encoded><![CDATA[<p>第一种方案:</p>
<pre>while true; do
    read -p "Do you wish to install this program?" yn
    case $yn in
        [Yy]* ) make install; break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac
done</pre>
<p>第二种方案:</p>
<pre>echo "Do you wish to install this program?"
select yn in "Yes" "No"; do
    case $yn in
        Yes ) make install; break;;
        No ) exit;;
    esac
done</pre>
]]></content:encoded>
			<wfw:commentRss>https://www.fushanlang.com/linux-shell-jiao-hu-yes-or-no-2247/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linux shell进程监控与自动重启</title>
		<link>https://www.fushanlang.com/linux-shell-jin-cheng-jian-kong-yu-zi-dong-zhong-qi-2236/</link>
		<comments>https://www.fushanlang.com/linux-shell-jin-cheng-jian-kong-yu-zi-dong-zhong-qi-2236/#comments</comments>
		<pubDate>Mon, 15 Oct 2012 03:32:52 +0000</pubDate>
		<dc:creator><![CDATA[fushanlang]]></dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[liunx]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.fushanlang.com/blog/?p=2236</guid>
		<description><![CDATA[<p>注意： （1）ps aux    显示系统全部进程，一行一个 （2）grep “abc”  从标准输入读取字符流，输出包含字符串“abc”的行 （3）grep -v &#8220;acb&#8221;   从标准输入读取字符流，输出不包含字符串“abc”的行 （4）wc -l        从标准输入读取字符流，输出行数</p> 检测进程httpd是否存在 <p>操作流程如下： （1）读取系统所有进程 （2）判断包含指定进程名字的信息是否存在 通过管道连接，命令如下：</p> <p>ps axu      &#124;    grep  &#8220;httpd&#8221;           &#124;      grep -v &#8220;grep&#8221;    &#124;      wc -l 所有进程&#8211;&#62;获取包含“httpd”的行&#8211;&#62;删除grep进程信息&#8211;&#62;输出最后的行数</p> <p>通过判断命令的执行结果是否为 0  ，可以知道进程是否存在。</p> <p>脚本如下: #!/bin/sh count=`ps axu &#124; <span style="color:#777"> . . . &#8594; Read More: <a href="https://www.fushanlang.com/linux-shell-jin-cheng-jian-kong-yu-zi-dong-zhong-qi-2236/">linux shell进程监控与自动重启</a></span>]]></description>
				<content:encoded><![CDATA[<p>注意：<br />
（1）ps aux    显示系统全部进程，一行一个<br />
（2）grep “abc”  从标准输入读取字符流，输出包含字符串“abc”的行<br />
（3）grep -v &#8220;acb&#8221;   从标准输入读取字符流，输出不包含字符串“abc”的行<br />
（4）wc -l        从标准输入读取字符流，输出行数</p>
<h2><strong>检测进程httpd是否存在</strong></h2>
<p>操作流程如下：<br />
（1）读取系统所有进程<br />
（2）判断包含指定进程名字的信息是否存在<br />
通过管道连接，命令如下：</p>
<p>ps axu      |    grep  &#8220;httpd&#8221;           |      grep -v &#8220;grep&#8221;    |      wc -l<br />
所有进程&#8211;&gt;获取包含“httpd”的行&#8211;&gt;删除grep进程信息&#8211;&gt;输出最后的行数</p>
<p>通过判断命令的执行结果是否为 0  ，可以知道进程是否存在。</p>
<p>脚本如下:<br />
#!/bin/sh<br />
count=`ps axu | grep &#8220;httpd&#8221; | grep -v &#8220;grep&#8221;| wc -l`<br />
if[$count -lt 1];then<br />
sudo /home/proudboy/apache/admin/restart.sh<br />
fi</p>
<p>注：还可以执行ps axu | grep &#8220;httpd&#8221; | grep -v &#8220;grep&#8221;，然后通过判断返回值是否为0来知道程序是否有输出，如下：<br />
#!/bin/sh<br />
count=`ps axu | grep &#8220;httpd&#8221; | grep -v &#8220;grep&#8221; `<br />
if[$? != &#8220;0&#8221;];then<br />
sudo /home/proudboy/apache/admin/restart.sh<br />
fi</p>
<p>接下来是如何让shell脚本定时执行的问题，有两种方式可以实现：<br />
（1）在shell里面做循环，例如：<br />
#/bin/sh<br />
while true; do<br />
if [ &#8220;$?&#8221; != &#8220;0&#8221; ]; then</p>
<p>fi<br />
sleep 2<br />
done<br />
（2）将shell脚本加入到corntab 或者 at 里面</p>
<h2>如下Shell脚本 实现了对tomcat6进程监控，如果不存在自动重启。</h2>
<pre>#!/bin/sh
pid=`ps aux| grep "tomcat6" | grep -v grep | sed -n  '1P' | awk '{print $2}'`
if [ -z $pid ]; then
        echo "begin restart,please waiting..."
        sudo /etc/init.d/tomcat6 restart
        exit 1
else
        echo -e "exist ,don't need restart"
fi</pre>
]]></content:encoded>
			<wfw:commentRss>https://www.fushanlang.com/linux-shell-jin-cheng-jian-kong-yu-zi-dong-zhong-qi-2236/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.392 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2026-05-16 21:56:40 -->
