coding_new has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!

I have a general question, and this may or may not be the forum (I apologize if it is not).

I have a perl script on a windows server, and I would like to run this script on multiple windows servers.

If I simply copy the script to all the servers, and have perl installed on all the serves, then I know it will run fine. However, I would like to have the script run from only one server, and go out to all the servers and return the data. Below is the script.

#!/usr/local/bin/perl #use Win32; use Win32::DriveInfo; use strict; use warnings; print "OS Information\n"; my $computer=Win32::NodeName(); print "The computer name is $computer\n"; my %dtypes=(0 => "Undertmined", 1 => "Does Not Exist", 2 => "Removable", 3 => "Hardrive", 4 => "Network", 5 => "CDROM", 6 => "RAM Disk"); print "Drive Information\n"; my @drives = Win32::DriveInfo::DrivesInUse(); foreach my $drive (@drives){ my $type=Win32::DriveInfo::DriveType($drive); print "Drive $drive is a $dtypes{$type}\n"; if (($drive eq 'C') | ($drive eq 'H')) { my ($sectors, $bytessec, $freeclust, $clustnum, $userfree, $total, $to +talfree)=Win32::DriveInfo::DriveSpace($drive); #divide bytes to get gigabytes; my $gbtotal = sprintf("%.2f", ($total/1073741824)); my $gbfree = sprintf("%.2f", ($totalfree/1073741824)); my $gbused = sprintf("%.1f", ($gbtotal - $gbfree)); my $free = $gbfree/$gbtotal; my $perfree = sprintf("%.2f", ($free * 100)); #Print output printf "$gbfree GB free from total of $gbtotal GB\n"; printf "total GB used $gbused\n"; printf "$perfree%% free on drive $drive\n"; printf "\n"; } else {} } exit;

What if any options are available for me to run this perl script on multiple windows servers succesfully? Thak you for your time and contributions

Replies are listed 'Best First'.
Re: Running Perl on Remote Windows Server
by dasgar (Priest) on Oct 14, 2014 at 15:01 UTC

    Unfortunately, you will need to have something on each remote server that runs locally on each one to collect the drive information that you're after. If you're not wanting to install and maintain Perl environments everywhere, you could use something like the pp utility from PAR::Packer to bundle your script into a stand alone executable that can be distributed and run on each system.

    However, you still need to find a way to remotely execute something on each server and retrieve outputs. Unfortunately, Windows does not automatically have something like a telnet or SSH server installed and running. There are couple of alternatives to installing a telnet or SSH server on each remote system. If have PowerShell installed (its part of newer Windows versions and can be installed on some older versions), PowerShell has an ability to issue commands to on remote Windows systems. I haven't done that myself, so I can't provide pointers on how to use PowerShell to do that.

    Another alternative is using PsExec from the SysInternals suite of tools available for free from Microsoft's web site.

    There are probably lots of other ways to remotely run programs on Windows systems, but the suggestions above are a good starting point.

      I was worried about that, and seems to be what I thought. Windows does not really seem to offer an easy SSH or telnet solution. Would have preferred something like that as I have worked with SSH on AIX boxes in the past and they seem to be more straight forward. Oh well on-wards to see what I can come up with! Thanks

Re: Running Perl on Remote Windows Server
by soonix (Chancellor) on Oct 14, 2014 at 15:08 UTC

    If you really want the script to run on multiple machines without having to install perl on them, you could use PAR::Packer and its pp.

    However, this essentially makes a copy of perl's runtime system and has to unpack it on every run. It does work, but start-up time is considerable.

    For the special case in the OP, I'd rather suggest going with WMI. One of the examples for DBD::WMI actually deals with remote machines...

Re: Running Perl on Remote Windows Server
by karlgoethebier (Abbot) on Oct 14, 2014 at 18:14 UTC
    printf "$gbfree GB free from total of $gbtotal GB\n"; printf "total GB used $gbused\n"; printf "$perfree%% free on drive $drive\n";

    Seems to be a monitoring task ;-)

    I don't know your environment but perhaps it is an option for you to set up a Linux box running Nagios?

    If so you could simply use SNMP and Nagios for gathering information about Windows drives etc. instead of bothering with remote execution, PAR::Packer a.s.o.

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

      Thanks Karl, unfortunately Linux box is not an option at this time in this environment

        As I remember (it has been a few years), Nagios can talk to probes on Windows machines just fine. Whether a Nagios monitoring host will live under Windows is a question that an appeal to the Doc may answer. At worst you could run Nagios on a Linux image inside a Windows Virtual machine (or use Cygwin).

        ----
        I Go Back to Sleep, Now.

        OGB

Re: Running Perl on Remote Windows Server
by Discipulus (Canon) on Oct 15, 2014 at 07:25 UTC
    welcome to the monastery coding_new and welcome to the 'win32 hell' too...
    In last decade i faced the same problem: administrering a win32 environement using Perl: even if i had not won i'm not defeated too..

    Here some consideration. There are tools that permit something like remotecommand, i avoid them because they are never safe. Even if billion of known bugs in this decade told us 'risk of remote code execution..' i was never able to use them.

    Winzoz force you to use his propietary tools to do such things. Is not that bad as you can imagine. For example i have many Perl programs parsing systems calls: it is not so elegant but tend to be very stable over the years.

    So you better use something that natively support remote execution. Some time ago i used 'wmi' to do such thing: wmi seemed to be the revolutionary thing at redmond (as today happen to powershell).

    Another viable option is having a Perl client server infrastructure, where the server ask in realtime to client info that you need. it is not so difficult to realize, but not so easy to maintain and upgrade.

    Here my old example of quering remote disks usin wmi (probably plagirazed from other monk..):
    use Win32::OLE('in'); use constant wbemFlagReturnImmediately => 0x10; use constant wbemFlagForwardOnly => 0x20; sub Logical_Disks { my $computer=shift; my %HoH = (); my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$compu +ter\\root\\CIMV2") or die "WMI connection failed.\n"; my $colItems = $objWMIService->ExecQuery("SELECT * FROM Win32_ +LogicalDisk", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly)||wa +rn $!; foreach my $objItem (in $colItems) { my @drivetype= ('Unknown', 'No RootDirectory', 'RemovableD +isk', 'LocalDisk', 'Network Drive', 'Compact Disc', 'RAM Disk'); #next if $objItem->{Name}->{'DriveType'} ne 'LocalDisk';#s +kip non logical disks $HoH{ $objItem->{Name} }{ 'DriveType' } =$drivetype[$objIt +em->{DriveType}] ; $HoH{ $objItem->{Name} }{ 'VolumeName' } = $objItem->{Volu +meName}; $HoH{ $objItem->{Name} }{ 'Size' } = $objItem->{Size}; $HoH{ $objItem->{Name} }{ 'FreeSpace' } = $objItem->{FreeS +pace}; } foreach my $key(keys %HoH){delete $HoH{$key} unless $HoH{$key}->{' +DriveType'} eq 'LocalDisk'} return \%HoH; }

    HtH
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.