Help with executing parallel sessions for same shell script with different but fixed parameters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with executing parallel sessions for same shell script with different but fixed parameters
# 1  
Old 12-07-2010
Java Help with executing parallel sessions for same shell script with different but fixed parameters

Hi Experts,

There is a shell script that accepts positional parameter between 1-25 to execute case statement of script depending upon the parameter passed.
Now I need to run all the 25 sessions parallely. In each option of case statement it is connecting with sqlplus and executing a select query but only one value changes in the where condition for a column as specified below.

e.g.
Code:
1)
sqlplus -s $ORA_CONN << EOF!
           SPOOL ${rep_name}report_${rep_part}_${sysdate1}.txt;
        SELECT * FROM customer WHERE col1=2001
           AND (  col2='sumthing')
        UNION
        SELECT * FROM customer WHERE col1=2001
        AND (condition);
        Spool off;
exit
EOF!
;;
2)
sqlplus -s $ORA_CONN << EOF!
           SPOOL ${rep_name}report_${rep_part}_${sysdate1}.txt;
        SELECT * FROM customer WHERE col1=2002
           AND (  col2='sumthing')
        UNION
        SELECT * FROM customer WHERE col1=2002
        AND (condition);
        Spool off;
exit
EOF!
;;

execution::
Code:
./script_name.ksh 1
./script_name.ksh 2
...
./script_name.ksh 25

But I want to execute this script parallely for all 25 options without opening separate shells.

Kindly help.

Many Thanks!

Last edited by Scott; 12-07-2010 at 07:13 AM.. Reason: Code tags
# 2  
Old 12-07-2010
run all scripts in background. create one script like below.

Code:
#!/bin/ksh
./script_name.ksh 1 &
./script_name.ksh 2 &
...
./script_name.ksh 25 &

then execute this script

./allScripts.ksh
This User Gave Thanks to For This Post:
R0H0N
# 3  
Old 12-07-2010
I have created a script as instructed above and ran it.
Can you please expain how this works.
Does it create different threads and execute it in different sessions.
For me its giving a big error in sql as its not able to decrypt the password.
There is a line to decrypt password and I have copied it in both main script and sunscript but still its not working. Its displaying as below.
username/@database
I don't know why but its not able to retain the password.
Since its not able to logon so its not executing the query.
May be I am not interpreting it correctly.
So I am pasting the big error below.
Code:
SQL*Plus: Release 10.2.0.2.0 - Production
reprompting on error.
 
Runs the specified SQL*Plus script from a web server (URL) or the
Copyright (c) 1982, 2005, Oracle. All Rights Reserved.
-M "<options>" Sets automatic HTML markup of output. The options
local file system (filename.ext) with specified parameters that
have the form:
will be assigned to substitution variables in the script.
Usage 1: sqlplus -H | -V
HTML [ON|OFF] [HEAD text] [BODY text] [TABLE text]
+ [ 0 -ne 0 ]
+ echo export report_run_date=07/12/2010
-H Displays the SQL*Plus version and the
[ENTMAP {ON|OFF}] [SPOOL {ON|OFF}] [PRE[FORMAT] {ON|OFF}]
usage help.
When SQL*Plus starts, and after CONNECT commands, the site profile
-R <level> Sets restricted mode to disable SQL*Plus commands
-V Displays the SQL*Plus version.
that interact with the file system. The level can
be 1, 2 or 3. The most restrictive is -R 3 which
(e.g. $ORACLE_HOME/sqlplus/admin/glogin.sql) and the user profile
Usage 2: sqlplus [ [<option>] [<logon>] [<start>] ]
disables all user commands interacting with the
(e.g. login.sql in the working directory) are run. The files may
<option> is: [-C <version>] [-L] [-M "<options>"] [-R <level>] [-S]
file system.
contain SQL*Plus commands.
-S Sets silent mode which suppresses the display of
 
-C <version> Sets the compatibility of affected commands to the
Refer to the SQL*Plus User's Guide and Reference for more information.
version specified by <version>. The version has
the SQL*Plus banner, prompts, and echoing of
the form "x.y[.z]". For example, -C 10.2.0
commands.
-L Attempts to log on just once, instead of
<logon> is: (<username>[/<password>][@<connect_identifier>] | /)
reprompting on error.
[AS SYSDBA | AS SYSOPER] | /NOLOG
-M "<options>" Sets automatic HTML markup of output. The options
have the form:
Specifies the database account username, password and connect
HTML [ON|OFF] [HEAD text] [BODY text] [TABLE text]
identifier for the database connection. Without a connect
[ENTMAP {ON|OFF}] [SPOOL {ON|OFF}] [PRE[FORMAT] {ON|OFF}]
identifier, SQL*Plus connects to the default database.
-R <level> Sets restricted mode to disable SQL*Plus commands
that interact with the file system. The level can
The AS SYSDBA and AS SYSOPER options are database administration
be 1, 2 or 3. The most restrictive is -R 3 which
privileges.
disables all user commands interacting with the
+ [ 0 -ne 0 ]
file system.
The /NOLOG option starts SQL*Plus without connecting to a
database.
-S Sets silent mode which suppresses the display of
the SQL*Plus banner, prompts, and echoing of
<start> is: @<URL>|<filename>[.<ext>] [<parameter> ...]
commands.
 
Runs the specified SQL*Plus script from a web server (URL) or the
<logon> is: (<username>[/<password>][@<connect_identifier>] | /)
local file system (filename.ext) with specified parameters that
will be assigned to substitution variables in the script.
[AS SYSDBA | AS SYSOPER] | /NOLOG
 
When SQL*Plus starts, and after CONNECT commands, the site profile
Specifies the database account username, password and connect
 
(e.g. $ORACLE_HOME/sqlplus/admin/glogin.sql) and the user profile
+ 0<<
identifier for the database connection. Without a connect
(e.g. login.sql in the working directory) are run. The files may
identifier, SQL*Plus connects to the default database.
contain SQL*Plus commands.
 
Refer to the SQL*Plus User's Guide and Reference for more information.
The AS SYSDBA and AS SYSOPER options are database administration
privileges.

Also where I can view the progress of threads.

Moderator's Comments:
Mod Comment Please use code tags

Last edited by Scott; 12-07-2010 at 07:17 AM..
# 4  
Old 12-07-2010
Quote:
Originally Posted by R0H0N
run all scripts in background. create one script like below.

Code:
#!/bin/ksh
./script_name.ksh 1 &
./script_name.ksh 2 &
...
./script_name.ksh 25 &

then execute this script

./allScripts.ksh

this is nothing but running all scripts in background. post how $ORA_CONN variable is being set?
R0H0N
# 5  
Old 12-08-2010
Many Thanks for your help.
Its working fine now as I have given statement sleep 30 in b/w the script call.
Earlier it was not getting enough time to run decrypt password script.

If I want to run the script with the parameter of a column value then how can I get it. I want to call script_name.ksh as many time as id in customer table and also pass it as a parameter to script.
someting Like below.


Code:
 
for i in select id from customer
do
./script_name.ksh $i &
done

---------- Post updated at 12:57 AM ---------- Previous update was at 12:13 AM ----------

I have figured out how to have ID from customer but now how to call shell script within for loop. Kindly help.
Code:
 
sqlplus -s $ORA_CONN <<EOF
SET SERVEROUTPUT ON
SET FEED OFF
spool abc.txt
BEGIN
   FOR i IN (SELECT ID FROM customer)
   LOOP
      DBMS_OUTPUT.put_line ( 'value ' || i.ID);
           END LOOP;
END;
/
spool off
EOF

# 6  
Old 12-08-2010
If I m not wrong, you are trying to execute same query for 25 column ids on a customer table at a single time.

For that your following qeury will list out column ids in abc.txt file. Correct?

Code:
sqlplus -s $ORA_CONN <<EOF
SET SERVEROUTPUT ON
SET FEED OFF
spool abc.txt
BEGIN
   FOR i IN (SELECT ID FROM customer)
   LOOP
      DBMS_OUTPUT.put_line ( 'value ' || i.ID);
   END LOOP;
END;
/
spool off
EOF

abc.txt will look like
Quote:
1
2
3
4
5
..
..
25
Now to execute same query as follows on all listed column ids, you can write a script like


Code:
#!/bin/ksh

    # First list out Column ids in abc.txt file
sqlplus -s $ORA_CONN <<EOF
SET SERVEROUTPUT ON
SET FEED OFF
spool abc.txt
BEGIN
   FOR i IN (SELECT ID FROM customer)
   LOOP
      DBMS_OUTPUT.put_line ( 'value ' || i.ID);
   END LOOP;
END;
/
spool off
EOF

    # Now for each data in abc.txt, execute second query in background
for myID in `cat abc.txt | xargs`
do
sqlplus -s $ORA_CONN <<EOF!
        SPOOL ${rep_name}report_${rep_part}_${sysdate1}.txt;
        SELECT * FROM customer WHERE col1="$myID"
           AND (  col2='sumthing')
        UNION
        SELECT * FROM customer WHERE col1="$myID"
        AND (condition);
        Spool off;
exit
EOF! &
done


Last edited by R0H0N; 12-08-2010 at 03:59 AM.. Reason: Highlight important points
This User Gave Thanks to For This Post:
R0H0N
# 7  
Old 12-09-2010
MySQL

Many Thanks for the advice.
Can this be implemented by dbms_scheduler package.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Executing SQL's in parallel

Hi Folks, I have requirement to pull a bunch of SQL's from a table in DB and execute them in parallel and update the status of each query as and when they complete. Can you please help me with ideas on how this can be achieved? create table list_of_sql ( id number, full_sql... (3 Replies)
Discussion started by: member2014
3 Replies

2. Shell Programming and Scripting

Parallel for in a Script Shell

Hello, This is my Script which configure a list of nodes. ( 40 nodes, and the configuration 10 minutes) #! /bin/sh if then echo "USE: ./start.sh nodes else nb_lignes=`wc -l $1 | cut -d " " -f1` echo "$nb_lignes machines" for i in $(seq $nb_lignes) //instructions done fi My... (2 Replies)
Discussion started by: chercheur111
2 Replies

3. Shell Programming and Scripting

Pass parameters to a function and running functions in parallel

Hi , I have a script which is using a text file as I/P. I want a code where it reads n lines from this file and pass the parameters to a function and now this script should run in such a way where a function can be called in parallel with different parameters. Please find below my script, it... (1 Reply)
Discussion started by: Ravindra Swan
1 Replies

4. Shell Programming and Scripting

Executing Multiple Queries in parallel in Shell

I have n number of SQL queries needs to executed in Shell. Result of this query need to assign in a variable. Once all the queries are executed script needs to exit. Sample Query: SQL 1: Select Count(*) from TABLE GROUP BY COL1,COL2 SQL 2: Select Count(*) from TABLE GROUP BY COL1,COL2 ... (2 Replies)
Discussion started by: Niranjancse
2 Replies

5. Shell Programming and Scripting

Parallel SQL sessions in shell script

i have 3 sqls , sql 1 and sql 2 shuld run in parallel , but sql 3 should run after completion f sql1 nd sql2, my code is as below, please suggest the changes sqlplus username1/password1@DB1 @sql >> log1 & sqlplus username2/password2@DB2 @sql2 >> log1 & how can i execute the... (7 Replies)
Discussion started by: only4satish
7 Replies

6. Shell Programming and Scripting

Executing two commands in parallel

Hi, I am stuck into a situation where i want to execute a command in my shell script well along with a previous command in order to achieve something but i am not figuring out a way. here is a snippet: service management restart rm -rf lock.file in the above, if you see, i am trying to... (5 Replies)
Discussion started by: sunrexstar
5 Replies

7. Shell Programming and Scripting

Optional Parameters/arguments while executing a script.

Hello, I have a shell script "Test.ksh" and I need to pass 8 parameters/arguments while executing the script ./Test.ksh 1 2 3 4 5 6 7 8 Out of these I want first 3 to be compulsory and rest 5 to be optional. Can you suggest the way to do this like and also how to pass these optional... (3 Replies)
Discussion started by: indrajit_u
3 Replies

8. Shell Programming and Scripting

Executing scripts in Parallel

Hi All, I have 3 shell scripts, Script1,Script2 and Script3. Now I want to run Script1 and Script2 in parallel and Script3 should depend on successful completion of both Script1 and Script2. Could you please suggest an approach of acheiving this... Thanks in advance (2 Replies)
Discussion started by: itsme_maverick
2 Replies

9. Shell Programming and Scripting

Run a same script in parallel with diffs parameters

i have script say some_script.ksh that takes an argument I need to run some_script.ksh in background parallely at the sametime with different arguments. Once all the background jobs complete, i need to run this script again in parallel with another 5 set of arguments. Would really... (1 Reply)
Discussion started by: hyennah
1 Replies

10. Shell Programming and Scripting

Problems executing SQL Plus sessions

If I execute this script: $ORACLE_HOME/bin/sqlplus -s <<EOF > oracle.log $DB_id/$DB_pswd@$DB_server start test.sql EOF the sql script executes with no errors. IF I execute the following script:... (12 Replies)
Discussion started by: mh53j_fe
12 Replies
Login or Register to Ask a Question