Posted on 2006-07-16 23:52
acooly 阅读(744)
评论(1) 编辑 收藏 所属分类:
脚本语言
在一个老系统的维护中,遇到经常因为数据库链接没有关闭,导致链接资源过大,造成系统经常挂掉,经分析是因为以前的开发人员在很多页面中没有关闭数据库连接造成的。但现在项目中的页面文件有上千个,为了检查出那些使用了数据库连接并没有关闭的页面,我写了下面的教本来递规目录中的页面文件并分析是否有满足条件的页面。
#!/bin/sh # check database connection state of jsp file
# check_conn # to call: check_conn file check_conn(){ if [ $# != 1 ]; then echo "Usage:check_conn file" return 1 fi _file=$1 if [ -f "$_file" -a -r "$_file" ] then _sedopen=`sed -n '/conn.jsp/p' $_file` _sedclose=`sed -n '/conn.close/p' $_file` if [ "$_sedopen" != "" -a "$_sedclose" = "" ] then echo $_file return 0 fi else echo "$_file can not be open" return 1 fi }
# recursion file list # tocall: ftree path logfile ftree(){ if [ $# != 2 ]; then echo "Usage:ftree path logfile" return 1 fi _dir=$1 _log=$2 if [ ! -d "$_dir" -o ! -r "$_dir" ] then echo "$_dir can not be operation." return 1 fi for file in `ls -1 $_dir` do if [ -d "$_dir/$file" ]; then (ftree $_dir/$file $_log) else echo $_dir/$file >> filelist ( if [ `echo $file|awk '{if($1~/^.*.jsp/) print 0}'` ]; then _check="`check_conn $_dir/$file`" if [ "$_check" != "" ]; then echo $_check >> $_log fi fi ) fi done return 0 } : # func progress bar # to call: procbar curval,maxval procbar(){ curval=$1 maxval=$2 barno=`expr 100 \* $curval / $maxval` count=0 while [ $count -lt $barno ] do echo -n "|" count=`expr $count + 1` sleep 1 done }
# BEGIN # procbar 5 30 FILEPATH=$1 LOGFILE=$2 if [ $# != 2 ]; then echo "Usage:checkfile FILEPATH LOGFILE" else ftree $FILEPATH $LOGFILE fi # END
|