Perl调用Shell模块
#!/usr/bin/perl -w
use strict;
use Shell;
my $sh = Shell->new;
print $sh->ifconfig;
my @pslines = ps("-ef|grep httpd|grep -v grep");
print @pslines;
print $sh->sed(" \"s/nameserver 210.73.64.1/nameserver 210.73.88.1/\" /etc/resolv.conf");
my $passwd = cat("/etc/passwd");
print $passwd;
cp("/etc/passwd", "/etc/passwd.orig");
说明:使用Shell模块时,还可以限定使用的命令范围,例如 use Shell qw(echo cat ps cp);
切记:shell语句的参数写在("xxx")中,复杂的shell语句中若有双引号必须使用转义字符,若有单引号是不能使用的,必须改成双引号。