简体   繁体   English

如何在Perl中检查已安装的Apache模块?

[英]How do I check an installed Apache module in Perl?

I'm writing a Perl script to check and see if a module is currently installed for Apache. 我正在编写一个Perl脚本来检查并查看当前是否为Apache安装了一个模块。 In Bash, I would use: 在Bash中,我会使用:

# httpd -M | grep fcgid
Syntax OK
fcgid_module (shared)

I want this to return a value of TRUE if that module exists and FALSE if it does not. 如果该模块存在,我希望它返回值TRUE,如果不存在则返回FALSE。 I'm running into a problem though, because httpd -M always outputs "Syntax OK." 我遇到了一个问题,因为httpd -M总是输出“Syntax OK”。

Here is what I 've got so far: 这是我到目前为止所得到的:

#!/usr/bin/perl
my $FCGID = "";
if (`httpd -M | grep fcgid`) {
$FCGID = "enabled"
} else {
$FCGID = "disabled"
}

The IF always evaluates as true though. IF总是评估为真。

About my configuration: 关于我的配置:

x86_64 GNU/Linux
# cat /etc/redhat-release
CentOS release 6.2 (Final)
# httpd -v
Server version: Apache/2.2.15 (Unix)
# perl -v
This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi

Open to suggestions. 接受建议。 I'm pretty new at Perl and still kinda new at Bash scripting. 我是Perl的新手,在Bash脚本编写方面仍然有点新鲜。

perl 2>/dev/null -le 'my @list = qx(httpd -D DUMP_MODULES ); print "FCGI found" if ( grep { $_ =~ /fcgi/ } @list )  '

It turns out I just need to redirect the output and I was confused about how to do that. 事实证明我只需要重定向输出,我对如何做到这一点很困惑。

$ httpd -M 2> /dev/null | grep fcgid_module
fcgid_module (shared)

So in PERL, I can evaluate that BASH expression and save it into a variable and test against the variable in the IF statement. 所以在PERL中,我可以评估该BASH表达式并将其保存到变量中并对IF语句中的变量进行测试。

my $FCGI = "";
my $FCGI_mod = `httpd -M 2> /dev/null | grep fcgid_module`;
if ( $FCGI_mod eq "" ) {
$FCGI = "disabled"
} else {
$FCGI = "enabled"
}

It's not the prettiest, but it does what I need it to. 它不是最漂亮的,但是我需要它。

Thank you to those who looked into it! 谢谢那些调查过它的人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM