Sed 为rsync和&;动态构建排除列表;egrep格式
我想知道是否有人能帮我解决一个问题 我编写了一组shell脚本,目的是基于审计服务器上的黄金构建来审计远程文件系统 作为其中的一部分,我做了以下工作: 1) 使用rsync生成任何新文件或目录、任何修改或删除的文件 2) 在本地和远程上使用Sed 为rsync和&;动态构建排除列表;egrep格式,sed,awk,find,rsync,grep,Sed,Awk,Find,Rsync,Grep,我想知道是否有人能帮我解决一个问题 我编写了一组shell脚本,目的是基于审计服务器上的黄金构建来审计远程文件系统 作为其中的一部分,我做了以下工作: 1) 使用rsync生成任何新文件或目录、任何修改或删除的文件 2) 在本地和远程上使用find${source\u filesystem}-ls,计算权限差异 现在,作为其中的一部分,我排除了某些文件或目录,即日志、跟踪文件等 因此,为了实现这一点,我使用了两种方法: 1) RSYNC-我有一个排除列表,它是使用--exclude from标志
find${source\u filesystem}-ls
,计算权限差异
现在,作为其中的一部分,我排除了某些文件或目录,即日志、跟踪文件等
因此,为了实现这一点,我使用了两种方法:
1) RSYNC-我有一个排除列表,它是使用--exclude from
标志添加的
2) find-ls
-我使用egrep-v
语句排除与rsync排除列表相同的内容:
e、 g.find-L${source_filesystem}-ls | egrep-v“$SEXCLUDE_supt”
所以我的问题是,我必须维护两个单独的列表,这是一个管理噩梦位
我正在寻求一些帮助或建议,以了解是否可以动态构建一个可用于rsync或find-ls
以下是排除列表的格式:
RSYNC:
*.log
*.out
*.csv
logs
shared
tracing
jdk*
8.6_Code
rpsupport
dbarchive
inarchive
comms
PR116PICL
**/lost+found*/
dlxwhsr*
regression
tmp
working
investigation
Investigation
dcsserver_weblogic_*.ear
dcswebrdtEAR_weblogic_*.ear
查找:
您不需要为
find
命令创建第二个列表grep
可以使用-f
标志处理模式列表。从手册中:
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file contains zero
patterns, and therefore matches nothing. (-f is specified by POSIX.)
下面是我要做的:
find -L ${source_filesystem} -ls | grep -Evf your_rsync_exclude_file_here
这也适用于包含换行符和空格的文件名。请告诉我进展如何。最后,grep-Evf有点像噩梦,因为rsync不支持regex,它使用regex,但不一样 因此,我接着继续我的另一个想法,通过解析rsync排除列表并动态构建变量以传递到egrep,动态地为egrep构建排除列表 这就是我使用的方法:
#!/bin/ksh
# Create Signature of current build
AFS=$1
#Create Signature File
crSig()
{
find -L ${SRC} -ls | egrep -v **"$SEXCLUDE"** | awk '{fws = ""; for (i = 11; i <= NF; i++) fws = fws $i " "; print $3, $6, fws}' | sort >${BASE}/${SIFI}.${AFS}
}
#Setup SRC, TRG & SCROOT
LoadAuditReqs()
{
export SRC=`grep ${AFS} ${CONF}/fileSystem.properties | awk {'print $2'}`
export TRG=`grep ${AFS} ${CONF}/fileSystem.properties | awk {'print $3'}`
export SCROOT=`grep ${AFS} ${CONF}/fileSystem.properties | awk {'print $4'}`
**export BEXCLUDE=$(sed -e 's/[*/]//g' -e 's/\([._+-]\)/\\\1/g' ${CONF}/exclude-list.${AFS} | tr "\n" "|")**
**export SEXCLUDE=$(echo ${BEXCLUDE} | sed 's/\(.*\)|/\1/')**
}
#Load Properties File
LoadProperties()
{
. /users/rpapp/rpmonit/audit_tool/conf/environment.properties
}
#Functions
LoadProperties
LoadAuditReqs
crSig
我使用它们来删除“*”和“/”,然后匹配我的特殊字符并在前面加上“\”以转义它们
然后使用“tr”将换行符替换为“|”,然后重新运行该输出以删除尾随的“|”,从而使变量$SEXCLUDE用于crSig函数中使用的egrep
你觉得怎么样?非常感谢这里的帮助,你知道RSYNC/GREP是否都支持regex吗?我想你把通配符和regex弄糊涂了。看见这就是为什么在两个不同的工具中使用相同的列表相当困难的原因。出于某种原因,它在我的文本中添加了一些**变量,请忽略这些。
#!/bin/ksh
# Create Signature of current build
AFS=$1
#Create Signature File
crSig()
{
find -L ${SRC} -ls | egrep -v **"$SEXCLUDE"** | awk '{fws = ""; for (i = 11; i <= NF; i++) fws = fws $i " "; print $3, $6, fws}' | sort >${BASE}/${SIFI}.${AFS}
}
#Setup SRC, TRG & SCROOT
LoadAuditReqs()
{
export SRC=`grep ${AFS} ${CONF}/fileSystem.properties | awk {'print $2'}`
export TRG=`grep ${AFS} ${CONF}/fileSystem.properties | awk {'print $3'}`
export SCROOT=`grep ${AFS} ${CONF}/fileSystem.properties | awk {'print $4'}`
**export BEXCLUDE=$(sed -e 's/[*/]//g' -e 's/\([._+-]\)/\\\1/g' ${CONF}/exclude-list.${AFS} | tr "\n" "|")**
**export SEXCLUDE=$(echo ${BEXCLUDE} | sed 's/\(.*\)|/\1/')**
}
#Load Properties File
LoadProperties()
{
. /users/rpapp/rpmonit/audit_tool/conf/environment.properties
}
#Functions
LoadProperties
LoadAuditReqs
crSig
**export BEXCLUDE=$(sed -e 's/[*/]//g' -e 's/\([._+-]\)/\\\1/g' ${CONF}/exclude-list.${AFS} | tr "\n" "|")**
**export SEXCLUDE=$(echo ${BEXCLUDE} | sed 's/\(.*\)|/\1/')**