Monday, April 14, 2014



 Submit a Task to Run in the Background

The nohup command can be used to submit a task as a background process. This is useful for long-running Oracle jobs, because it frees up your command prompt so that you can do other work. It is especially useful when you are dialed in to an Oracle server using a modem, and you want to free up your terminal session.

Assume that you have a script named run_sql.ksh that executes SQL*Plus commands. The following nohup command can be used to submit that script for background processing:

>> nohup run_sql.ksh > logfile.lst 2>&1 &


There's obviously more to this command than just nohup, and it's important to understand just what each element of the command is doing. For this example, the elements are as follows:

a)nohup :
Submits the task so that it continues to run even after you disconnect your terminal session.
 
b)run_sql.ksh
Specifies the Unix shell script that you want to run in the background.

c) logfile.lst
Redirects standard output to the specified file.

d)2 > &1
Redirects standard error messages to the standard output device. The 2 represents the
standard error device, and 1 represents the standard output device.

e)&
Runs the task in the background.

You need to have a space in front of the trailing ampersand (&) character, and it's that & that causes the task to run as a background task. The nohup command is frequently used with background tasks, because without it all your background tasks would terminate the moment you logged off of Unix.

The nohup command allows a task to continue running long after you've logged off and gone home for the night .


2) Ensure That Only the Oracle User Can Run a Script 

The following if statement will ensure that a Unix script is executed only by the Unix user named
oracle :
if [ `whoami` != 'oracle' ]
then
   echo "Error: You must be oracle to execute."
   exit 99
fi
This statement offers extra security and protection against unauthorized execution. For example, a
script that shuts down the Oracle database should be executed only by the Oracle user. While Unix
permissions offer execution protection, good Unix programmers will also ensure that the proper user

is running the script. 

No comments:

Post a Comment