Linux 在httpd.conf中收集网站并获取文件夹大小的脚本

Linux 在httpd.conf中收集网站并获取文件夹大小的脚本,linux,perl,bash,sh,Linux,Perl,Bash,Sh,在此处输入代码我想做的是一个脚本,它将收集在我的httpd.conf中配置的网站。 获取DoccumentRoot和ServerName。然后对文档根目录执行du-s,并将数据放入文件中 现在我有这个命令: grep -E "DocumentRoot|ServerName" /etc/httpd/conf/httpd.conf | grep -v "#" | awk '{print $2}' 它在单独的行上给我输出,但我不知道如何解析输出,以便我可以在DocumentRoot上执行du-s,然

在此处输入代码我想做的是一个脚本,它将收集在我的
httpd.conf
中配置的网站。 获取
DoccumentRoot
ServerName
。然后对文档根目录执行
du-s
,并将数据放入文件中

现在我有这个命令:

grep -E "DocumentRoot|ServerName" /etc/httpd/conf/httpd.conf | grep -v "#" | awk '{print $2}'
它在单独的行上给我输出,但我不知道如何解析输出,以便我可以在
DocumentRoot
上执行
du-s
,然后在新文件的同一行上获得
Size/DocumentRoot/ServerName

所需的输出应类似于:

size - Folder -  Servername

3436712 /etc/www/htdocs/domain www.domain.qc.ca
尝试这样做:

grep -E "DocumentRoot|ServerName" /etc/httpd/conf/httpd.conf |
awk '!/#/{print $2}' |
xargs -n1 du -s 
或使用独特的管道:

grep -ioP '^\s*(?<!#)\s*(DocumentRoot|ServerName)\s+\K.*' /etc/httpd/conf/httpd.conf |
xargs -n1 du -s 

grep-ioP'^\s*(?感谢您的回复,当我尝试唯一管道时,我得到了一个错误:grep:unrecogned character after(?<)和du-s被执行。对于grep-E,我得到了一个/:Event not found。问题与awk'!/#/{print$2}有关“没有awk,它可以工作,但有了它,我得到了错误。谢谢你可以将它更改为grep-v^#这是上面的awk部分。因为所做的只是在开始时删除任何匹配项,我设法使它工作,但问题是:因为我grep了DocumentRoot和ServerName,我的grep输出看起来像这样:'DocumentRoot/etc/www。”/htdocs/domain ServerName www.domain.qc.ca DocumentRoot/etc/www/htdocs/site ServerName www.site.org DocumentRoot/etc/www/htdocs/bob ServerName www.bob.ca’因此,对于xargs du-s,我每两行就有一个错误,最后我希望有这样的输出:3436712/etc/www/htdocs/domainwww.domain.qc.caDon我不知道这是什么意思,但我在回复中添加了
-n
切换到
xargs
,这样会更好