<?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>PHPMan--Live and learn &#187; bash</title>
	<atom:link href="http://www.phpman.com.cn/archives/tag/bash/feed" rel="self" type="application/rss+xml" />
	<link>http://www.phpman.com.cn</link>
	<description>不积跬步,无以至千里;不积小流,无以成江海</description>
	<lastBuildDate>Wed, 28 Jul 2010 02:39:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>初试手了下bash编程,定期清除日志</title>
		<link>http://www.phpman.com.cn/archives/289</link>
		<comments>http://www.phpman.com.cn/archives/289#comments</comments>
		<pubDate>Wed, 21 Oct 2009 06:38:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[system related]]></category>
		<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://www.phpman.com.cn/?p=289</guid>
		<description><![CDATA[由于公司网站的日志文件按天为目录存放，格式如下
20090901
20090902
……
时间一长，硬盘老暴满，正好前些天看过点shell的知识，应用一下^_^

#!/bin/bash
#日志保留月份数
reserveMonth=2
#需保存的最早一天的日志
oldest=`date -d &#34;-$reserveMonth month&#34; +%Y%m%d`
#日志存放目录
workdir='/home/phpman/test'
#搜索目录
dirs=`ls $workdir -F &#124; grep -P '\d{8}/' &#124; sed 's/.$//'`
for i in $dirs;do
#早于最早那天的，删除
    if test $i -le $oldest
    then
        tmp_dir=${workdir}/$i
#记录此次操作的记录
        echo &#34;Directory '$tmp_dir' deleted at `date '+%Y-%m-%d %H:%M:%S'`&#34; &#62;&#62; ${workdir}/delete.log
  [...]]]></description>
		<wfw:commentRss>http://www.phpman.com.cn/archives/289/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
