- 论坛徽章:
- 0
|
主要偶们软件的系统文件总是莫名其妙被一些不知道不熟悉unix和系统的管理员改掉或者删掉,所以写了一个shell。
这个的意思是,第一次先对/usr/local/mysys下面的目录和文件作一次扫描,记录一下文件的大小和时间.
lf5 /usr/local/mysys /etc/filelist /tmp/report backup
这个的意思是根据以前生成的/etc/filelist的内容去比较/usr/local/mysys里面的内容,将报告输出到/tmp/report里面.
lf5 /usr/local/mysys /etc/filelist /tmp/report
初初学shell,乱写一通,多指点
- #!/bin/sh
- #if the number of parameters equal to 4,then only backup.
- #echo "usuage:lf <compare path> <backup file path> <output file path> [backup]"
- #
- clear
- echo "************************************"
- echo "*Files Compare Tool *"
- echo "*VERSION:0.15 *"
- echo "*10/15/2003---11/07/2003 *"
- echo "************************************"
- echo "\n"
- echo `date`
- echo "\n"
- if [ $# -eq 4 ]
- then
- cd $1
- find . -type f -print |xargs ls -l|awk '{printf"%-45s %-9s %s%s%s\n",$9,$5,$6,$7,$8}' > $2
- echo "the backup file list is in the dir "$2
- exit
- elif [ $# -lt 3 ]
- then
- echo "usuage:lf <compare path> <backup path> <output file path> [backup]"
- exit
- fi
- #calculate the total files
- count=0
- while read line
- do
- count=`expr $count + 1`
- #echo $count
- echo "\033[22;12H: \c"$count"\c"
- echo $count
- ofilename=` echo $line|awk '{print $1}' `
- ofilesize=` echo $line|awk '{print $2}' `
- ofiledate=` echo $line|awk '{print $3}' `
- #result=` ls -l $ofilename`
- #echo $result
- #if echo $result|grep "No such" >/dev/null
- if [ -f $ofilename ]
- then
- result=` find $ofilename|xargs ls -l`
- nfilename=` echo $result|awk '{print $9}' `
- nfilesize=` echo $result|awk '{print $5}' `
- nfiledate=` echo $result|awk '{printf"%s%s%s\n",$6,$7,$8}' `
- if [ $ofilesize != $nfilesize ] || [ $ofiledate != $nfiledate ]
- #size or date not equal
- then
- echo $ofilename $ofilesize $ofiledate|awk '{printf"< %-45s %-9s %s\n",$1,$2,$3}' >>$3
- echo $nfilename $nfilesize $nfiledate|awk '{printf"> %-45s %-9s %s\n",$1,$2,$3}' >>$3
- fi
- else
- echo $ofilename "not exist"|awk '{printf"%-45s %-9s %s\n",$1,$2,$3}' >>$3
- fi
- done < $2
- #end of the comparing
- echo "\n"
复制代码 |
|