-4

I have requirement where in I have to find OS running on remote machine in perl. The machine can be running on any OS from windows, linux to aix. I have seen few solutions but unfortunately all requires to install third part tool which cannot be done in this case.

Can you please guide me to some way to get the remote machine OS details (name and version) without need to install third party tool.

Tejas
  • 272
  • 2
  • 7
  • 15

2 Answers2

2

You have a remote machine R and a local machine L. What exactly are you doing?

  • Running a Perl script on machine L that accesses remote machine R.
  • Running a program on machine L that runs a Perl script on machine R.

If you're doing the second scenario, take a look at the Config module. This is a standard Perl module, and has been included in all versions of Perl since at least Perl 5.8. There are hundreds of parameters that you can pull up. Take a look at osname and osver.

It's pretty simple to use:

use Config;   #Imports $Config hash

print "Operating system is $Config{osname}\n";
print "The version of the OS is $Config{osvers}\n";
David W.
  • 105,218
  • 39
  • 216
  • 337
  • Hi David... Thanks you for reply.. I am looking for option 1. I want to run a perl script on local machine. Which will fetch me the OS of the remote machine. – Tejas Sep 01 '11 at 17:27
1

If you can log in to each remote machine and if perl is installed on that machine, then just parse the output of perl -V. For example

$ perl -V
Summary of my perl5 (revision 5 version 12 subversion 0) configuration:

  Platform:
    osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
    uname='Win32 strawberryperl 5.12.0.0 #1 Wed Apr 28 11:51:06 2010 i386'
    ....
mob
  • 117,087
  • 18
  • 149
  • 283
  • Thanks for replying, But my problem still remains same. Because connecting to machine without knowing its OS is the first roadblock. How can I connect to remote machine without knowing whether its windows or linux.. and that also in perl – Tejas Aug 25 '11 at 19:22
  • 1
    If you knew some machine was a Windows machine, how would you log in to it? If you knew it was linux, how would you log in to it? Why isn't the answer to this question just (1) try to log in to machine as if it was Windows, if it doesn't work go to step 2 (2) try to log in as if it were a linux machine, if it doesn't work go to step 3 (3) try to log an as if it were a ... – mob Aug 25 '11 at 19:46