- 论坛徽章:
- 0
|
请问如何在Linux下,通过perl模块,获取远程windows机器的信息?(不使用telnet)
我看了一些例子,通过Win32::OLE和DBD::WMI,来获取WINDOWS机器的CPU等信息,但是这些例子上的脚本,应该都是在windows上运行的,因为在linux上,无法安装Win32::OLE和DBD::WMI这两个模块。
请问在Linux下能够使用wmi来连接到远程windows吗?
或者有没有其他方法,能够在linux下使用perl,来获取远程windows信息?
比如说CPU使用率,某个进程状态,等等
谢谢!
以下是我查询到的windows上的perl脚本,希望能找到Linux上的相应解决方法,谢谢!
use Win32::OLE qw[in];
my $host = $ARGV[0] || '.';
my $wmi = Win32::OLE->GetObject( "winmgmts://$host/root/cimv2" )
or die Win32::FormatMessage( Win32::OLE::LastError() );
my %instances = (
Win32_PhysicalMemory => &get_pmem,
Win32_PerfRawData_PerfOS_Memory => &get_amem,
Win32_Processor => &get_load,
Win32_LogicalDisk => &get_disk,
);
my $out = get_perf_data();
print "$out\n";
sub get_perf_data {
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = $year + 1900;
$mon = $mon + 1;
my $str = sprintf "%4.4d-%2.2d-%2.2d",$year,$mon,$mday;
my $timestr = sprintf "%2.2d:%2.2d:%2.2d",$hour,$min,$sec;
my $mem;
foreach ( keys %instances ) {
my $class = $wmi->InstancesOf( $_ );
$mem .= $instances{ $_ }->( $class );
}
my $out = "##nCollect Time: ".$str." ".$timestr."n".$mem."%%rn";
return $out;
}
# get cpu loadavg
sub get_load {
my $class = shift;
my $total="";
my $i = 0;
$i++,$total = $total."CPU No. $i: ".$_->{LoadPercentage}."%n" foreach in($class);
return $total;
}
# get total memory size
sub get_pmem {
my $class = shift;
my $total;
$total += $_->{Capacity} foreach in($class);
return "Physical Memory: $total Bytesn";
}
# get available memory size
sub get_amem {
my $class = shift;
my $amem;
$amem .= join ' ', $_->{AvailableBytes} foreach in($class);
return "Available Memory: $amem Bytesn";
}
# get free disk sizes
sub get_disk {
my $class = shift;
my $total = "";
$total .= "DISK ".$_->{DeviceID}." Free: ".$_->{FreeSpace}." Bytesn" foreach in($class);
return $total;
} |
|