.bash_history not recording host/os command executed from >SQL prompt

Latest response

Red Hat Enterprise Linux Server release 6.7 (Santiago) is the OS version

$ sqlplus

SQL> !hostname -i

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@exaoem01 ~]$ history

1012 sqlplus
1013 history

From the above example It is evident that any os commands executed from "SQL> " prompt are not recorded not sure why. How can I audit or force these commands to be visible in .bash_history . Appreciate your insight.



as sqlplus is launching its own process and you are executing those commands inside that process, bash is not aware of their execution.

Maybe you are looking for something like this


See Will's post above. One thought though, let's say you know you're about to begin a procedure on a server you wish to keep a record of for later reference, perhaps to document steps or something. If you do know this in advance, you can use script -a /path/to/file.txt which will record all commands and output until the time you execute a ctrl c to interrupt the recording process. Read the man page for the usage of script -a /path/to/some/file.txt

Excerpt of man page:

       script makes a typescript of everything displayed on your terminal.
       It is useful for students who need a hardcopy record of an
       interactive session as proof of an assignment, as the typescript file
       can be printed out later with lpr(1).

       If the argument file is given, script saves the dialogue in this
       file.  If no filename is given, the dialogue is saved in the file

Different shells operate in different history contexts. While you're using bash to launch the sqlplus shell, what happens within sqlplus is opaque to bash. The sqlplus shell has its own history mechanisms you can leverage, but they are wholly separate from bash's.

You might look at some combination of sqlplus's hist and spool commands to save out your sql monitor's history to a file, but don't really know any other built-in methods for dumping history and (potentially) redirecting to disk. Note: the hist command was introduced in Oracle 12, I believe, so if you're using an older version of Oracle, you may be outta luck (for built-in tools).