Sponsored Content
Top Forums Shell Programming and Scripting Pass a DDL statement to a KSH script Post 302449116 by agama on Saturday 28th of August 2010 02:01:44 PM
Old 08-28-2010
This should give you enough of an idea of how to write the script. This example assumes Ksh (Korn shell) as bash has issues with piping command output to read into variable names.

Code:
#!/usr/bin/env ksh
while [[ -n $1 ]]       # for each string on the command line
do
        echo "$1" | read cmd1 cmd2 table_name sub_cmd column_name junk
        if [[ $1" "$2 == "ALTER TABLE" ]]
        then
                if [[ $sub_cmd == "ADD" ]]
                then
                        database_command "select 1 from USER_TABLES where table_name = $table_name and column_name = ${column_name/\(/}" | wc -l | read count
                        # assuming that one record out from database command is a good response and any other amount of output is not
                        if (( $count != 1 ))
                        then
                                echo "error verifying $1"
                        else
                                echo "verified: $1"
                        fi
                fi
        fi

        shift
done

I have no way to actually test this, but it does pass syntax checking by the shell.

Have fun.
This User Gave Thanks to agama For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass variable to SQLPLUS in a ksh script?

Hi, I am writing a ksh script which will use sqlplus to run a sql and pass 2 variables as the SQL request. In the ksh script, I have 2 variables which are $min_snap and $max_snap holding 2 different numbers. Inside the same script, I am using SQLPLUS to run an Oracle SQL script,... (6 Replies)
Discussion started by: rwunwla
6 Replies

2. Shell Programming and Scripting

Help with if statement in ksh script

I need a way to grep for a string in a file and if it finds it, to print set a variable to "Yes", if it doesn't find the string in a file to set the variable to "No". I plan on using these variables to print a table that lists whether the string was found or not. For example print "File ... (2 Replies)
Discussion started by: stepnkev
2 Replies

3. Shell Programming and Scripting

I can't seem to pass variables properly into a nawk statement

Ok, So up front I'm going to say that I'm a very elementary scripter, and I tend to use tools I don't fully understand, but I shotgun at something until I can get it to work...that said, I can't for the life of me understand why I can't get this to go down the way I want it to. The goal: -to... (6 Replies)
Discussion started by: DeCoTwc
6 Replies

4. Shell Programming and Scripting

how to use if statement in ksh script

Hi, I need to compare two variables using if condition and i am not sure if am right or wrong. My code is like : if then echo "new file" else echo "old file and remove it" fi where both variables contain time : filetime contains the time when a file... (2 Replies)
Discussion started by: manmeet
2 Replies

5. Shell Programming and Scripting

How to call an sql script inside a while statement in KSH

Hi all, I'm trying to run an sql inside a loop which looks like this #!bin/ksh while IFS=, read var1 var2 do sqlplus -s ${USERNAME}/${PASSWORD}@${ORACLE_SID} << EOF insert into ${TABLE} ( appt_date ) values ( '${var1 }' ); ... (6 Replies)
Discussion started by: ryukishin_17
6 Replies

6. Shell Programming and Scripting

How to use loop to convert a DML statement into DDL?

Hi Unix Gurus, I am a newb. I am creating a script which will use an input file. This input file can have 1 or more than 1 DML staments like INSERT/DELETE/UPDATE. I have to execute these statements using my script but before execution of these DML statements, I need to check the count for... (17 Replies)
Discussion started by: ustechie
17 Replies

7. Shell Programming and Scripting

How to pass tablenames from a file to shell script to execute create statement in DB2

Hi, I am new to Shell Scripting, and I need to create nicknames for 600 tables in db2. I have the file names in a text file and i have to pass these table names to a shell script create nicknames in db2. Can some one please help me in this regard. (1 Reply)
Discussion started by: kamalanaatha
1 Replies

8. Shell Programming and Scripting

ksh script trying to pass a variable to edit a file

I'm trying to create a ksh script that will ask the user for the port number. $PORT1 is the variable I want to use that will contain whatever numbers the user inputs. The script would edit ports.txt file, search and delete "./serv 110.1.0.1.$PORT1 200;=3" . So if the user types 50243 then the... (5 Replies)
Discussion started by: seekryts15
5 Replies

9. UNIX for Dummies Questions & Answers

How to pass cat file in awk statement?

Hi, I am working on kernel parameters, want to check values under /proc/sys/kernel below I tried for kernel.sem SEMMNS: 4096 cat /proc/sys/kernel/sem | awk '{print $2}' awk '{ if ($2 < 33000) print }' /proc/sys/kernel/sem |awk '{print $2}' 32000 The above... (7 Replies)
Discussion started by: stew
7 Replies

10. Shell Programming and Scripting

How to pass and read an array in ksh shell script function.?

I'm able to read & print an array in varaible called "filelist" I need to pass this array variable to a function called verify() and then read and loop through the passed array inside the function. Unfortunately it does not print the entire array from inside the funstion's loop. #/bin/ksh... (5 Replies)
Discussion started by: mohtashims
5 Replies
MDBTools(1)															       MDBTools(1)

NAME
mdb-schema - Generate schema creation DDL SYNOPSIS
mdb-schema [options] database [backend] DESCRIPTION
mdb-schema is a utility program distributed with MDB Tools. It produces DDL (data definition language) output for the given database. This can be passed to another database to create a replica of the original access table format. OPTIONS
-T <table>, --table <table> Single table option. Create schema for this table only. Default is to export all tables. -N namespace Prefix identifiers with namespace. --drop-table Issue DROP TABLE statement. --no-drop-table Don't issue DROP TABLE statement. This is the default. --not-null Issue NOT NULL constraints. This is the default. --no-not-null Don't issue NOT NULL constraints. --default-values Issue DEFAULT values. --no-default-values Don't issue DEFAULT values. This is the default. --not-empty Issue CHECK <> '' constraints. --no-not-empty Don't issue CHECK <> '' constraints. This is the default. --indexes Export INDEXes. This is the default. --no-indexes Don't export INDEXes. --relations Export foreign keys constraints. This is the default. --no-relations Don't export foreign keys constraints. backend Specifies target DDL dialect. Supported values are access, sybase, oracle, postgres, and mysql. If not specified the generated DDL will be in access format. ENVIRONMENT
MDB_JET3_CHARSET Defines the charset of the input JET3 (access 97) file. Default is CP1252. See iconv(1). MDBICONV Defines the output charset to use for the SQL file. Default is UTF-8. mdbtools must have been compiled with iconv. MDBOPTS semi-column separated list of options: o use_index o no_memo o debug_like o debug_write o debug_usage o debug_ole o debug_row o debug_props o debug_all is a shortcut for all debug_* options NOTES
HISTORY
mdb-schema first appeared in MDB Tools 0.1. SEE ALSO
gmdb2(1) mdb-export(1) mdb-hexdump(1) mdb-prop(1) mdb-sql(1) mdb-ver(1) mdb-array(1) mdb-header(1) mdb-parsecsv(1) mdb-tables(1) AUTHORS
The mdb-schema utility was written by Brian Bruns and others. BUGS
Relationships and other features may not be supported by all databases. Access datatypes are mapped to their closest counterparts in the target backend. This may not always yield an exact fit. 0.7 13 July 2013 MDBTools(1)
All times are GMT -4. The time now is 10:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy