Setting the Command Editor- Configuring an Efficient Environment
You can use the set – o command to make your command-line editor be either vi or emacs. This example sets the command-line editor to be vi:
Now, when you press Esc+K, you’re placed in a mode in which you can use vi commands to search through the stack of previously entered commands.
For example, if you want to scroll up the command stack, you can use the K key; similarly, you can scroll down using the J key. When in this mode, you can use the slash (/) key and then type a string to be searched for in the entire command stack.
Tip Before you attempt to use the command editor feature, be sure you’re thoroughly familiar with either the vi or emacs editor.
A short example will illustrate the power of this feature. Say you know that you ran the ls -altr command about an hour ago. You want to run it again, but this time without the r (reverse-sort) option. To enter the command stack, press Esc+K:
You should now see the last command you executed. To search the command stack for the ls command, type /ls, and then press Enter or Return:
The most recently executed ls command appears at the prompt:
To remove the r option, use the right arrow key to place the prompt over the r on the screen, and press X to remove the r from the end of the command. After you’ve edited the command, press the Enter or Return key to execute it.
Developing Standard Scripts
If the Oracle Database environment has been around for long time, there are probably database administration teams that have developed hundreds of scripts and utilities to help manage an environment. Many of the scripts are now available in tools and other DBA utilities even if they were developed in house. Having too many scripts and utilities pulls you away from other important data management tasks and does not simplify the environment as the new versions of the database is available. To take advantage of the new database features and simplify the administration utilities, it is better to use a small set of focused scripts, with each script usually less than 50 lines long. You can also look at the new database tools that are also released with the various versions of the database. If you develop a script that another DBA can’t understand or maintain, then it loses its effectiveness. Also, if you have to execute a command more than a couple of times, a script should be created to execute it. If it is something that is now a standard, regular check, or job, the script can be used to automate the process.
These scripts are handy to put into jobs that will be automatically run or during a time of troubleshooting since it needs to be completed quickly. There are other tools that also maintain databases and provide proactive alerts and monitoring of multiple databases instead of a script being run against one database at a time.
This section contains several short shell functions, shell scripts, and SQL scripts that can help you manage a database environment. This is by no means a complete list of scripts—rather, it provides a starting point from which you can build. Each subsection heading is the name of a script.
Note Before you attempt to run a shell script, ensure that it’s executable. use the chmod command to achieve this: chmod 750 <script> or chmod u+x <script>.