You are asking the wrong question.You should be asking how to write a bash script that runs sql trhough the database.
If that is really what you want to do you need to first write a script that sets up your environment variables. Including: ORACLE_HOME, TNS_ADMIN, ORACLE_SID, and maybe ORACLE_BASE. Then all you need to do is add this to a script, making sure to keep the leading period and space. That tells the shell to apply the environment variables to the current shell and not to a shell that gets created and dropped after the script finishes.
Now all you need to do is call sqlplus and give it the commands. As in this example:Code:. /oracle/bin/set_oracle_enrivonment.sh sidname
The above code will analyze a schema and then exit. "<< EOF" is the key it tells Oracle run every command between the start and EOF as if it was typed into a sqlplus session. It doesn't have to be EOF it could be anything, it just has to be the same anything. If you strategy depends on you pressing control-c to end it how will you ever schedule jobs using cron? And when using cron you need to make sure that your script has everything that it needs to run. That is every environment variable set.Code:export USER=$2 # Log into the DB through SQLPLUS. You must be the oracle user. $ORACLE_HOME/bin/sqlplus -s '/ as sysdba' << EOF set term off set echo off set feedback off alter session set cursor_sharing=exact; begin dbms_stats.gather_schema_stats (ownname=>'$2',granularity=>'ALL',cascade=>true); end; / exit EOF




You should be asking how to write a bash script that runs sql trhough the database.
Reply With Quote