Sponsored Content
Top Forums Shell Programming and Scripting Run different SQL on multiple DBs using SHELL script Post 302880381 by CarloM on Thursday 19th of December 2013 07:41:34 AM
Old 12-19-2013
You need to provide some more details - like what database it is & how you're accessing it, where the list of DBs is, where the SQL scripts are, etc.

Just as an example that might help - a very rough (untested) solution, assuming Oracle/SQLPlus, a file with SIDs, and SQL files (only) in a single dir, and the same DB user everywhere:
Code:
SQLDIR=/someplace/sqls
DATADIR=/someplace/data
LOGDIR=/someplace/log
DBUSER=someuser
DBPASSWD=horriblyinsecure

for DBSID in $(< "${DATADIR}/sids.lst" )
do
   SQLPREFIX=$(echo "$DBSID" | cut -c1-2)
   for SQLFILE in "${SQLDIR}/${SQLPREFIX}"*
   do
      sqlplus ${DBUSER}/${DBPASSWD}@${DBSID} <<EOH
set stuff
spool "${LOGDIR}/${SQLFILE}.out"
@${SQLFILE}
quit;
EOH
   done
done

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run an SQL script inside a shell

How do I create a K Shell which would silently (without user input) logon to Oracle and run an SQL script? Any help will be greatly appreciated. Steve (1 Reply)
Discussion started by: stevefox
1 Replies

2. Shell Programming and Scripting

shell script to run .sql files

hi Friends, Please help me in writing shell script to run list of sql files. database is Oracle 9i, unix os is solaris Requirement is 1. sql file must take two inputs a)feed id and b)business date 2.shell script must out put .xls or .csvfile as out put without trimming any column name and... (1 Reply)
Discussion started by: balireddy_77
1 Replies

3. Shell Programming and Scripting

Run Sql plus in shell script

Hello, I want to connect to ssh, run a query, and store that into a variable in the shell script. Also I need to pass the variable back to php to display the query results. I have created a public/private key pair for ssh connection and that is working fine. Also I am able to run query in the... (8 Replies)
Discussion started by: shekhar2010us
8 Replies

4. Shell Programming and Scripting

How to run a SQL select query in Oracle database through shell script?

I need to run a SQL select query in Oracle database and have to capture the list of retrieved records in shell script. Also i would like to modify the query for certain condition and need to fetch it again. How can i do this? Is there a way to have a persistent connection to oracle database... (9 Replies)
Discussion started by: vel4ever
9 Replies

5. Shell Programming and Scripting

Run SQL thru shell script: how to get a new line when run sql query?

Hi, this's Pom. I'm quite a new one for shell script but I have to do sql on shell script to query some information from database. I found a concern to get a new line...When I run my script, it retrieves all data as wondering but it's shown in one line :( What should I do? I'm not sure that... (2 Replies)
Discussion started by: Kapom
2 Replies

6. Shell Programming and Scripting

Shell script to run sql query having a long listing of parameters

Hi, I have a query regarding execution of a sql query having long listing of parameters ..I need to execute this query inside a shell script. The scenario is like.... Suppose I have a file abc.txt that has the card numbers..it could be in thousands.. then I need to fire a query like ... (12 Replies)
Discussion started by: vsachan
12 Replies

7. Shell Programming and Scripting

run sql queries from UNIX shell script.

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX? :confused: (1 Reply)
Discussion started by: 24ajay
1 Replies

8. Shell Programming and Scripting

Run a sql script on multiple $Oracle_SID at once and send an alert if reaches the threshold

I am trying to accomplish following tasks in my KSH script: Run a sql script on multiple $ORACLE_SID at once Sends an alert only if the threshold > 2 for any of the $ORACLE_SID Please advice as to how I can approach this!! Thanks in advance! (1 Reply)
Discussion started by: jd_2000
1 Replies

9. Shell Programming and Scripting

Run sql query in shell script and output data save as delimited text

I want to run sql query in shell script and output data save as delimited text (delimited text would be comma) Code: SPOOL_FILE=/pgedw/dan.txt SQL=/pgedw/dan.sql sqlplus -s username/password@myhost:port/servicename <<EOF set head on set COLSEP , set linesize 32767 SET TRIMSPOOL ON SET... (8 Replies)
Discussion started by: Jaganjag
8 Replies

10. UNIX for Beginners Questions & Answers

How to apply the update statement in multiple servers on multiple dbs at a time .?

Hi , Can any please help the below requirement on all multiple servers and multiple dbs. update configuration set value='yes' ;1) the above statement apply on 31 Databases at a time on different Ip address eg : 10.104.1.12 (unix ip address ) the above ip box contains 4 db's eg : db... (2 Replies)
Discussion started by: venkat918
2 Replies
SWF_CLOSEFILE(3)							 1							  SWF_CLOSEFILE(3)

swf_closefile - Close the current Shockwave Flash file

SYNOPSIS
void swf_closefile ([int $return_file]) DESCRIPTION
Close a file that was opened by the swf_openfile(3) function. PARAMETERS
o $return_file - If set then the contents of the SWF file are returned from the function. RETURN VALUES
No value is returned. EXAMPLES
Example #1 Creating a simple flash file based on user input and outputting it and saving it in a database <?php // The $text variable is submitted by the // user // Global variables for database // access (used in the swf_savedata() function) $DBHOST = "localhost"; $DBUSER = "sterling"; $DBPASS = "secret"; swf_openfile("php://stdout", 256, 256, 30, 1, 1, 1); swf_definefont(10, "Ligon-Bold"); swf_fontsize(12); swf_fontslant(10); swf_definetext(11, $text, 1); swf_pushmatrix(); swf_translate(-50, 80, 0); swf_placeobject(11, 60); swf_popmatrix(); swf_showframe(); swf_startdoaction(); swf_actionstop(); swf_enddoaction(); $data = swf_closefile(1); $data ? swf_savedata($data) : die("Error could not save SWF file"); // void swf_savedata(string data) // Save the generated file a database // for later retrieval function swf_savedata($data) { global $DBHOST, $DBUSER, $DBPASS; $dbh = @mysql_connect($DBHOST, $DBUSER, $DBPASS); if (!$dbh) { die (sprintf("Error [%d]: %s", mysql_errno(), mysql_error())); } $stmt = "INSERT INTO swf_files (file) VALUES ('$data')"; $sth = @mysql_query($stmt, $dbh); if (!$sth) { die (sprintf("Error [%d]: %s", mysql_errno(), mysql_error())); } @mysql_free_result($sth); @mysql_close($dbh); } ?> SEE ALSO
swf_openfile(3). PHP Documentation Group SWF_CLOSEFILE(3)
All times are GMT -4. The time now is 05:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy