<?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[Php或者Shell 脚本修改crontab实例]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Unix/LinuxC技术]]></category>
<pubDate>Thu, 10 Mar 2011 04:06:06 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	在linux上的crontab文件中我已有一行，如10 * * * * root /var/www/html/test.php<br/>现在我要通过编写php程序来修改10 * * * * root /var/www/html/test.php<br/>变成22 10 * * * root /var/www/html/aa.php<br/>问题解决了，不过有点傻瓜，不知谁还有什么更好的方法吗？若有，希贴上来，互相学习<br/>问题解决了，不过有点傻瓜，不知谁还有什么更好的方法吗？若有，希贴上来，互相学习<br/><div class="code">$fp=fopen(&quot;/etc/crontab&quot;,&quot;rb&quot;);<br/>$save=fopen(&quot;/home/mysql/crontab&quot;,&quot;wb&quot;);<br/>$i=0;<br/>/*foreach ($f as $v)<br/>&#123;<br/>&nbsp;&nbsp;$t = preg_replace(&#039;13 15 * * * root /usr/bin/php /var/www/html/mysqlbackup/testClient.php&#039;, &#039;* * *&#039;, $v);<br/>&nbsp;&nbsp;$result&#91;&#93; = $t;<br/>&#125;*/<br/>while (!feof($fp)) &#123;<br/>&nbsp;&nbsp;$buffer = fgets($fp);<br/>&nbsp;&nbsp;fwrite($save,$buffer);<br/>&nbsp;&nbsp;$i=$i+1;<br/>&nbsp;&nbsp;if ($i==10)&#123;<br/>&nbsp;&nbsp;fwrite($save,&quot;success&quot;);<br/>&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&#125;<br/>fclose($fp);<br/>fclose($save);<br/>$fp=fopen(&quot;/etc/crontab&quot;,&quot;wb&quot;);<br/>$save=fopen(&quot;/home/mysql/crontab&quot;,&quot;rb&quot;);<br/>$i=0;<br/>while (!feof($save)) &#123;<br/>&nbsp;&nbsp;$buffer = fgets($save);<br/>&nbsp;&nbsp;fwrite($fp,$buffer);&nbsp;&nbsp; <br/>&nbsp;&nbsp;&#125;<br/>fclose($fp);<br/>fclose($save);</div><br/><br/>Shell修改Crontab的方法：<br/>脚本一：<br/><div class="code">#!/bin/bash <br/>#cron_file=&#039;/home/zary/b&#039;; <br/>cron_tmp=&#039;/home/zary/d&#039;; <br/>cronpath=&quot;/home/zary/b&quot;; <br/>cronbak=&#039;/home/zary/f&#039;; <br/>parameter=; <br/>if &#91; &quot;$parameter&quot; = &quot;change&quot; &#93; <br/>then <br/>cp $cronpath $cronbak; <br/>sed -e &#039;/c_check_mysqlstatus&#92;.sh/s/^#//&#039; -e &#039;/c_check_webstatus&#92;.sh/s/^#//&#039; &#92; <br/>-e &#039;/c_syscheck&#92;.sh/s/#//&#039; -e &#039;/c_syscheck&#92;.sh/s/^11/#11/&#039; $cronpath &gt;$cron_tmp; <br/>cp $cron_tmp $cronpath; <br/>crontab $cronpath; <br/>elif &#91; &quot;$parameter&quot; = &quot;resume&quot; &#93; <br/>then <br/>sed -e &#039;/c_check_webstatus&#92;.sh/s/^/#/&#039; -e &#039;/c_check_mysqlstatus&#92;.sh/s/^/#/&#039; &#92; <br/>-e &#039;/c_syscheck&#92;.sh/s/^#//&#039; -e &#039;/c_syscheck&#92;.sh/s/^&#92;*&#92;/20/#&#92;*&#92;/20/&#039; $cronpath &gt;$cron_tmp; <br/>cp $cron_tmp $cronpath; <br/>crontab $cronpath; <br/>else <br/>echo &quot;Usage: c_startcron.sh &#91;change/resume&#93;&quot;; <br/>fi</div><br/><br/>脚本二：<br/><br/><div class="code">#!/bin/bash <br/>cronpath=&quot;/var/spool/cron/root&quot;; <br/>if &#91; = &#039;tw&#039; &#93; <br/>then <br/>kick=&quot;tw_mail.php&quot;; <br/>elif &#91; = &quot;nw&quot; &#93; <br/>then <br/>kick=&quot;nw_mail.php&quot;; <br/>elif &#91; = &quot;pw&quot; &#93; <br/>then <br/>kick=&quot;pw_mail.php&quot;; <br/>fi <br/>crontab -l&#124;egrep -v &quot;$kick&quot;&gt;/tmp/crontab; <br/>case &quot;&quot; in <br/>daily) <br/>date=&quot; * * *&quot;; <br/>; <br/>weekly) <br/>date=&quot; * * 1&quot;; <br/>; <br/>monthly) <br/>date=&quot; * 1 *&quot;; <br/>; <br/>esac <br/>cat /tmp/crontab &gt; $cronpath; <br/>if &#91; = &quot;on&quot; &#93; <br/>then <br/>echo &quot;$date /usr/local/php5/bin/php /home/htdocs/pukicn/new/OM/Cron/$kick&quot;&gt;&gt;$cronpath; <br/>fi</div><br/>来源：<br/>http://topic.csdn.net/u/20090918/14/29cb3abf-6de6-4cc6-a28b-26f234b2a87b.html<br/>http://www.linuxdiyf.com/viewarticle.php?id=14751
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] Php或者Shell 脚本修改crontab实例]]></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>