newbie01.perl has asked for the wisdom of the Perl Monks concerning the following question:

Hello to the Perl Highness ... :-)

I need to write some monitoring script for servers that is a combination of AIX, Solaris, Linux and Micro$oft.

I am guessing there shouldn't be any issue with the *nixes flavors but unfortunately Micro$oft will surely give me troubles? For example, filesystem checks for space will surely be different as I cannot run df on Micro$oft.

Had anyone attempted this sort of "experiment" before or can put me into which gates to go to for what am trying to achieve?

Your guidance will be very much appreciated

Replies are listed 'Best First'.
Re: Need tips on portable Perl programming
by clp (Friar) on Nov 20, 2009 at 07:45 UTC

    See Automating System Administration with Perl, it has lots of info on Perl on different platforms.

    If you can use Cygwin on your Ms Windows machines, it can provide a nice Perl environment and many other tools & features that you find on the *nix machines. If you've never used Cygwin, give yourself some time to install & configure it, and to become aware of its idiosyncracies.

Re: Need tips on portable Perl programming
by codeacrobat (Chaplain) on Nov 20, 2009 at 06:52 UTC
    perlport should provide useful information.

    print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});
Re: Need tips on portable Perl programming
by cdarke (Prior) on Nov 20, 2009 at 08:56 UTC
    You give the example of df, and you are right. So avoid calling external programs as far as possible. Try and use internal Perl commands, or use modules that are portable.

    $^O ($OSNAME) is a useful variable to test on those occasions when you have to. When you have to use different modules depending on the platform, see the often forgotten pragma if, for example:
    use if ($^O eq 'MSWin32'), 'Win32::Process'; use if ($^O ne 'MSWin32'), 'POSIX';
      Please don't do that in the general case (it may work for whatever Win32::Process does, I don't know). Assuming that everything that isn't Windows is the same is Wrong. Use Devel::CheckOS to check for things like "is this Windows?" or "is this Unix?" or "is this VMS?" or ...
      <o> Hi,

      I totally agree with what you said below:

      "You give the example of df, and you are right. So avoid calling external programs as far as possible. Try and use internal Perl commands, or use modules that are portable."

      Now, my next question is "Is there any such Perl module or library that allows you to run one single command but somehow "clever" enough to run either the Windows command or the UNIX command?"

      It's kinda like using alias command on UNIX to map the most command Windows/DOS command into its UNIX equivalent command. If such a module exists, then perhaps that may do the trick.

      To illustrate it further, maybe there is a Perl module where I say clearscr and then inside the Perl module, it will run cls if the OS is Windows or clear if the OS is *nix? Am I making this node more confusing?