递归目录的shell脚本

#! /bin/sh

# 在其他目录运行时一定要加上这样的语句
# 尤其是配置在crontab里自动运行
cd `dirname $0` 

#定义数据别名
alias statdb="/usr/local/mysql -h ... -uppstat -p... statdb"

# 递归访问目录
# 如果文件名中包含指定日期
# 则将文件当作SQL脚本入库
function show()
{
        for i in $1/* # 因为博客园的代码插件有BUG,为了显示效果追加*/
        do
                if [ -d $i ]; then
                        echo $i "is directory"
                        show $i $2 # 递归
                else
                        j=`echo $i | awk '{print index($0,"'$2'")}'`
                        if [ $j -gt 0 ]; then
                                cat $i | statdb -f
                        fi
                fi
        done #遍历指定目录下文件
}

# 调用
show "/work/stat/read/statdb" "20131208"
原文地址:https://www.cnblogs.com/code-style/p/3465063.html