Which operating system am I running?

This is an easy way to find the operating system where runs a script, of course, there are other ways more smart, but I created this function on Oracle 7.3, about 1999, then it was not so easy. Note that ASM does not fit. We use the first datafile created (System tablespace) to find the OS type. Works on WINDOWS, UNIX / Linux and OpenVMS. We need access to DBA_DATA_FILES.

This is the code;

CREATE OR REPLACE
FUNCTION GET_OPERATING_SYSTEM RETURN VARCHAR IS
  I                PLS_INTEGER;
  LongChain        PLS_INTEGER;
  FileName         VARCHAR2(513);
  Character        CHAR;
BEGIN
   SELECT FILE_NAME
   INTO FileName
   FROM DBA_DATA_FILES
   WHERE FILE_ID = 1;
   LongChain := LENGTH (FileName);
   I := 1;
   WHILE (I <= LongChain)  LOOP
     Character := SUBSTR (FileName, i, 1);
  IF Character = ‘\’ THEN
     RETURN (‘WINDOWS’);
  END IF;
  IF Character = ‘/’ THEN
     RETURN (‘UNIX/Linux’);
  END IF;
  IF Character = ‘[‘ THEN
     RETURN (‘OpenVMS’);
  END IF;
  I := I + 1;
   END LOOP;
END;
/

 

Eg.;

QUE_OS_ESTOY_2

 

Antonio NAVARRO

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s