|
UNIX - Process in backgroundIt is very useful to run Unix commands in the background if it is going to take a long time to process or if you are working from a remote system, with dial up connection (you never know when your computer disconnects!!). It is very easy to submit a job in the background in Unix. A "&" at the end of the command puts the process into background. One requirement is that the job cannot be interactive. Let's consider you need to take a database export in the background. The command would be
here the parameter file has all the required parameters, including the username and password (make sure you have the permissions on the password file set to 600, so that other user cannot read this file). The output from the export is redirected to a file /tmp/exp.out. Now the problem is if you, terminate the session, the background process also will die, because the process we started is a child of this parent shell. The solution would be to tell UNIX, not to hang up, even if I terminate the parent session. It is done by using the command "nohup".
Here is an idea to run SQL scripts or PL/SQL procedures in the background. To run these, you need to login to the database. The following script will run a SQL script, which is passed in as a parameter, without displaying the username and password in the process list. (To see the oracle process list, do "ps -ef | grep ora", or to see the sqlplus sessions do "ps -ef | grep sqlplus")
To run mysql.sql script using the about script, in the background, the command would be
Since the username and password are in the second line, it will not be visible in the process list. As earlier make sure the file permissions are 700 (chmod 700 runscript.sh). You may even add a line towards the end of runscript.sh to page you when the script run is complete, so that you do not have to baby sit some long running processes.
|