вторник, 27 января 2026 г.

visudo - description of what each column means

su -
visudo
Description what each column means
#-----------------------------------------------
# john ALL = (ALL:ALL) NOPASSWD: ALL
#  ^    ^      ^   ^              ^
#  |    |      |   |              |
# user  | all users|              |
#     host         |       all commands
#              all groups
#-----------------------------------------------
oracle  ALL=(ALL)       NOPASSWD: ALL

Install btop on Oracle Linux 8

To install btop++ on Oracle Linux 8, you can use the dnf package manager after enabling the EPEL repository.

Method 1: Using the EPEL Repository (Recommended)

The easiest way to install btop++ is by using the Extra Packages for Enterprise Linux (EPEL) repository.
1. Install the EPEL repository:
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

🛈 This command adds the EPEL repository configuration to your system.

2. Install btop
Once the repository is enabled, you can install btop (the executable name for btop++) using dnf:
sudo dnf install btop
3. Run btop:
btop

UTLcmd PL/SQL package as wrapper of Java RunTime.exec method with read stdin, stdout, stderr outputs

Go to required Container(PDB)

SQL>
DEFINE s_container='CDB$ROOT';
--DEFINE s_container='PDB1';
--DEFINE s_container='PDB2';


ALTER SESSION SET container = &&s_container;

show con_name

Original UTLcmd PL/SQL package as wrapper of Java RunTime.exec method

/*
   Build by Vadim Loevski of Quest Software.
*/   
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "UTLcmd" AS
import java.lang.Runtime;
public class UTLcmd
{
  public static void execute (String command)
  {
   try
      {
       Runtime rt = java.lang.Runtime.getRuntime();
       rt.exec(command);
      }
   catch(Exception e)
   {
    System.out.println(e.getMessage());
    return;
   }
  }
}
/

CREATE OR REPLACE PACKAGE UTLcmd IS
  PROCEDURE execute (cmd IN VARCHAR2) AS LANGUAGE JAVA NAME
           'UTLcmd.execute(java.lang.String)';
END;
/


/*======================================================================
| Supplement to the fifth edition of Oracle PL/SQL Programming by Steven
| Feuerstein with Bill Pribyl, Copyright (c) 1997-2009 O'Reilly Media, Inc. 
| To submit corrections or find more code samples visit
| http://oreilly.com/catalog/9780596514464/
*/

Improved version of UTLcmd PL/SQL package as wrapper of Java RunTime.exec method with read stdin, stdout, stderr outputs

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "UTLcmd" AS
import java.lang.Runtime;
import java.lang.Process;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class UTLcmd
{
  public static void execute (String command)
  {
   try
      {
        Runtime rt = java.lang.Runtime.getRuntime();
        Process proc = rt.exec(command);

        BufferedReader stdInput = new BufferedReader(new 
             InputStreamReader(proc.getInputStream()));
        
        BufferedReader stdError = new BufferedReader(new 
             InputStreamReader(proc.getErrorStream()));
        
        // Read the output from the command
        System.out.println("Here is the standard output of the command:\n");
        String s = null;
        while ((s = stdInput.readLine()) != null) {
            System.out.println(s);
        }
        
        // Read any errors from the attempted command
        System.out.println("Here is the standard error of the command (if any):\n");
        while ((s = stdError.readLine()) != null) {
            System.out.println(s);
        }       
      }
   catch(Exception e)
   {
    System.out.println(e.getMessage());
    return;
   }
  }
}
/
 
CREATE OR REPLACE PACKAGE UTLcmd IS
  PROCEDURE execute (cmd IN VARCHAR2) AS LANGUAGE JAVA NAME
           'UTLcmd.execute(java.lang.String)';
END;
/

🛈 Create Java source "UTLcmd" and PL/SQL package ULTcmd in required schema (SCOTT for example). In this article both versions like "Original" & "Improved with read stdin, stdout, stderr outputs" was created and tested in SYS/SYSTEM schemas, in this case provide next grant to required user/schema to able execute PL/SQL UTLcmd package:

GRANT EXECUTE ON UTLcmd TO SCOTT;

Example of using improved version of UTLcmd PL/SQL package with read stdin, stdout, stderr outputs

CALL DBMS_JAVA.SET_OUTPUT (1000000);
exec UTLcmd.execute('du -hs /u01');
Here is the standard output of the command:
141G	/u01
exec UTLcmd.execute('ls -lht /u01');
Here is the standard output of the command:

total 24K
drwxr-xr-x 9 oracle oinstall 4.0K Jan 26  2026 app
Next command don't works, I don't know why but looks like it don't understand "*"
exec UTLcmd.execute('du -hs /u01/*');
Here is the standard output of the command:

Here is the standard error of the command (if any):

/bin/du: cannot access '/u01/*': No such file or directory

FILE_LIST_API.list - List Files in a Directory From PL/SQL and SQL using Java class FileListHandler

References:


I chose a variation suggested by Christian Antognini which passes back an array:

Java class FileListHandler

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "FileListHandler" AS
import java.io.File;
import java.lang.Exception;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Array;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.OracleDriver;
 
public class FileListHandler
{
  public static Array list (String path) throws Exception {
    Path directory = Paths.get(path);
    if (!Files.isDirectory(directory))
      throw new Exception("path argument does not reference a directory (" + path + ")");
 
    File[] files = directory.toFile().listFiles();
    OracleConnection connection = (OracleConnection)(new OracleDriver()).defaultConnection();
    return connection.createOracleArray("T_VARCHAR2_ARR", files);
  }
};
/

PL/SQL package file_list_api with function list

CREATE OR REPLACE TYPE t_varchar2_arr AS TABLE OF VARCHAR2(500);
/


CREATE OR REPLACE PACKAGE file_list_api AS

FUNCTION list (p_path  IN  VARCHAR2) RETURN t_varchar2_arr
AS LANGUAGE JAVA
NAME 'FileListHandler.list (java.lang.String) return java.sql.Array';
 
END file_list_api;
/
Example of using:
SELECT * FROM table(FILE_LIST_API.list ('/u01/app/oracle/admin/orcl/adump/'));
Another implementing of FILE_LIST_API.list PL/SQL function in fDelete PL/SQL function as wrapper of Java JDelete.delete method for delete files from OS

fDelete PL/SQL function as wrapper of Java JDelete.delete method for delete files from OS

Define in PL/SQL Java source named JDeleteFile for Java class JDelete:
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "JDeleteFile" AS
import java.io.File;
public class JDelete {
  public static int delete (String fileName) {
    File myFile = new File (fileName);
    boolean retval = myFile.delete();
    if (retval) return 1; else return 0;
  }
}
/
Create PL/SQL function fDelete as wrapper of Java JDelete.delete method
CREATE FUNCTION fDelete (file IN VARCHAR2)
  RETURN NUMBER
AS LANGUAGE JAVA NAME 'JDelete.delete (java.lang.String) return int';
Example of using:
SQL> EXEC DBMS_OUTPUT.PUT_LINE (fdelete('/u01/app/oracle/admin/orcl/adump/ora_some_file.aud'));
Before use fDelete function to avoid file permissions errors like:
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception: java.security.
AccessControlException: the
Permission (java.io.FilePermission /u01/app/oracle/admin/orcl/adump/ora_some_file.aud delete) has not been
granted to SCOTT. The PL/SQL
to grant this is dbms_java.grant_permission( 'SCOTT', 'SYS:java.io.FilePermission',
'/u01/app/oracle/admin/orcl/adump/ora_some_file.aud', 'delete' )
need grants permission to access files in a required directory:
CALL DBMS_JAVA.grant_permission(
  'SYSTEM',
  'SYS:java.io.FilePermission',
  '/u01/app/oracle/admin/orcl/adump/*',
  'read,write,delete'
);
fDelete function can delete just concrete specified file name (names which you know), if you want delete all files *.aud in directory then need use FILE_LIST_API.list described in List Files in a Directory From PL/SQL and SQL using Java class FileListHandler to get all file names list:
DECLARE
  res pls_integer;
BEGIN
  FOR rec in (SELECT * FROM table(FILE_LIST_API.list ('/u01/app/oracle/admin/orcl/adump/')) where rownum <= 10000)
  LOOP
    res := fdelete(rec.column_value);
    /*
    if res = 1 then
      DBMS_OUTPUT.PUT_LINE (rec.column_value || ' is ' || 'deleted');
    else
      DBMS_OUTPUT.PUT_LINE (rec.column_value || ' ' || 'not found/error');
    end if;
    */
  END LOOP;
END;
/
Note: Oracle9i Database Release 2 introduced an enhanced version of the UTL_FILE package that, among other things, allows you to delete a file using the UTL_FILE.FREMOVE procedure. It also supports file copying (FCOPY) and file renaming (FRENAME).