当前位置: 技术问答>linux和unix
AIX系统shell问题
来源: 互联网 发布时间:2017-03-12
本文导语: shell如下: #!/bin/ksh ## 开发环境与标准环境文件对比 ## ## DPATH="/cbsdep" SPATH="/depstd" RPATH=`pwd` #Sdirs=" src inc proc mss std etc tools " Sdirs=" ss " #Filetypes=" *.SQC *.ccs *.c *.pc *.h *.sql makefile *.del *.sh dbtable.txt yy.data ...
shell如下:
#!/bin/ksh
## 开发环境与标准环境文件对比
##
##
DPATH="/cbsdep"
SPATH="/depstd"
RPATH=`pwd`
#Sdirs=" src inc proc mss std etc tools "
Sdirs=" ss "
#Filetypes=" *.SQC *.ccs *.c *.pc *.h *.sql makefile *.del *.sh dbtable.txt yy.data "
Filetypes=" *.del "
TODAY=`date +%Y%m%d%H`
Listfile=$RPATH/chklist.txt_$TODAY
Rptfile=$RPATH/difflist.txt_$TODAY
Detail=$RPATH/rptdetail.txt_$TODAY
echo $Filetypes
genlist()
{
>$Listfile
cd $DPATH
for ft in $Filetypes
do
for dn in $Sdirs
do
echo $dn $ft >>$RPATH/a.txt
echo " find $dn -name $ft -print >> $Listfile "
find $dn -name $ft -print >> $Listfile
done
done
# cat $Listfile |grep -v "bak/" >$HOME/tmp/_ttttt_diffvers
# mv $HOME/tmp/_ttttt_diffvers $Listfile
}
echo PID=$$
echo "RBCS 源码核对 -----=>"
echo "源码清单文件: $Listfile"
echo "差异文件清单: $Rptfile"
echo "差异详细文件: $Detail"
## generate diff list
echo "建立核对文件清单 ........"
genlist
echo "建立核对文件清单 OK "
## diff source files
cd $RPATH
echo "差异清单: " >$Rptfile
echo " " >>$Rptfile
echo "差异详细: " >$Detail
echo "($DPATH) : " >>$Detail
echo "------------------------------------------------------- " >>$Detail
echo "------------------------------------------------------- " >>$Detail
echo "核对文件................"
echo "---------------------------------------------------------"
cat $Listfile|while read cfile
do
echo "diff $DPATH/$cfile $SPATH/$cfile ...... "
diff $DPATH/$cfile $SPATH/$cfile 1>>/dev/null 2>>/dev/null
if [ $? = 0 ]
then
echo $cfile is same
else
if [ $? = 1 ]
then
echo $cfile has difference !!
echo $cfile >>$Rptfile
echo "---------------------------------------->: $cfile " >>$Detail
diff $DPATH/$cfile $SPATH/$cfile >> $Detail
else
echo $SPATH/$cfile not exist !!
echo $cfile >>$Rptfile
echo "---------------------------------------->: $cfile " >>$Detail
echo $SPATH/$cfile not exist !! >>$Detail
fi
fi
done
echo "核对文件 done !! "
echo "PLS check $Rptfile $Detail "
-----------------------------------------shell结束-----------------------
运行结果:
*.del
PID=5550220
RBCS 源码核对 -----=>
源码清单文件: /cbsdep/user/wz/tmp/chklist.txt_2012082113
差异文件清单: /cbsdep/user/wz/tmp/difflist.txt_2012082113
差异详细文件: /cbsdep/user/wz/tmp/rptdetail.txt_2012082113
建立核对文件清单 ........
find ss -name 000502.del -print >> /cbsdep/user/wz/tmp/chklist.txt_2012082113
建立核对文件清单 OK
核对文件................
---------------------------------------------------------
核对文件 done !!
PLS check /cbsdep/user/wz/tmp/difflist.txt_2012082113 /cbsdep/user/wz/tmp/rptdet
ail.txt_2012082113
------------------------------------运行结果结束----------------
问题:
如期望结果不符合,期望结果是搜索出cbsdep用户ss目录下的del结尾的文件和depstd的ss目录下del结尾的文件比较,然后记录差别写入文件。
不过现在的问题是,find命令无法按照期望的找到那些del结尾的文件,如结果所示,find语句实际为 find ss -name 000502.del。期望应该是 find ss -name "*.del"。实在不明白为啥“*”变成了“000502”,求高手指导
#!/bin/ksh
## 开发环境与标准环境文件对比
##
##
DPATH="/cbsdep"
SPATH="/depstd"
RPATH=`pwd`
#Sdirs=" src inc proc mss std etc tools "
Sdirs=" ss "
#Filetypes=" *.SQC *.ccs *.c *.pc *.h *.sql makefile *.del *.sh dbtable.txt yy.data "
Filetypes=" *.del "
TODAY=`date +%Y%m%d%H`
Listfile=$RPATH/chklist.txt_$TODAY
Rptfile=$RPATH/difflist.txt_$TODAY
Detail=$RPATH/rptdetail.txt_$TODAY
echo $Filetypes
genlist()
{
>$Listfile
cd $DPATH
for ft in $Filetypes
do
for dn in $Sdirs
do
echo $dn $ft >>$RPATH/a.txt
echo " find $dn -name $ft -print >> $Listfile "
find $dn -name $ft -print >> $Listfile
done
done
# cat $Listfile |grep -v "bak/" >$HOME/tmp/_ttttt_diffvers
# mv $HOME/tmp/_ttttt_diffvers $Listfile
}
echo PID=$$
echo "RBCS 源码核对 -----=>"
echo "源码清单文件: $Listfile"
echo "差异文件清单: $Rptfile"
echo "差异详细文件: $Detail"
## generate diff list
echo "建立核对文件清单 ........"
genlist
echo "建立核对文件清单 OK "
## diff source files
cd $RPATH
echo "差异清单: " >$Rptfile
echo " " >>$Rptfile
echo "差异详细: " >$Detail
echo "($DPATH) : " >>$Detail
echo "------------------------------------------------------- " >>$Detail
echo "------------------------------------------------------- " >>$Detail
echo "核对文件................"
echo "---------------------------------------------------------"
cat $Listfile|while read cfile
do
echo "diff $DPATH/$cfile $SPATH/$cfile ...... "
diff $DPATH/$cfile $SPATH/$cfile 1>>/dev/null 2>>/dev/null
if [ $? = 0 ]
then
echo $cfile is same
else
if [ $? = 1 ]
then
echo $cfile has difference !!
echo $cfile >>$Rptfile
echo "---------------------------------------->: $cfile " >>$Detail
diff $DPATH/$cfile $SPATH/$cfile >> $Detail
else
echo $SPATH/$cfile not exist !!
echo $cfile >>$Rptfile
echo "---------------------------------------->: $cfile " >>$Detail
echo $SPATH/$cfile not exist !! >>$Detail
fi
fi
done
echo "核对文件 done !! "
echo "PLS check $Rptfile $Detail "
-----------------------------------------shell结束-----------------------
运行结果:
*.del
PID=5550220
RBCS 源码核对 -----=>
源码清单文件: /cbsdep/user/wz/tmp/chklist.txt_2012082113
差异文件清单: /cbsdep/user/wz/tmp/difflist.txt_2012082113
差异详细文件: /cbsdep/user/wz/tmp/rptdetail.txt_2012082113
建立核对文件清单 ........
find ss -name 000502.del -print >> /cbsdep/user/wz/tmp/chklist.txt_2012082113
建立核对文件清单 OK
核对文件................
---------------------------------------------------------
核对文件 done !!
PLS check /cbsdep/user/wz/tmp/difflist.txt_2012082113 /cbsdep/user/wz/tmp/rptdet
ail.txt_2012082113
------------------------------------运行结果结束----------------
问题:
如期望结果不符合,期望结果是搜索出cbsdep用户ss目录下的del结尾的文件和depstd的ss目录下del结尾的文件比较,然后记录差别写入文件。
不过现在的问题是,find命令无法按照期望的找到那些del结尾的文件,如结果所示,find语句实际为 find ss -name 000502.del。期望应该是 find ss -name "*.del"。实在不明白为啥“*”变成了“000502”,求高手指导
|
用find ss|grep .del$ 代替可以吗?
|
cd $DPATH
for ft in $Filetypes #这里循环*.del ,000502.del符合条件,则ft为000502.del,输出000502不足为奇。
for ft in $Filetypes #这里循环*.del ,000502.del符合条件,则ft为000502.del,输出000502不足为奇。