Yes, you can pass the string in the way you have it in your example. With quotes round the whole string it will be addressable in the script as $1 (first parameter from the command line).
How you parse it really depends on what you need to do with it. A simple mechanism would be to use the set command:
The result of the set command is that each token from the string in $1 will be assigned to $1 through $n. You then can examine/use the tokens as you need to .
A small example to illustrate the set command:
The results when t22 -- my test script -- is executed are:
Hope this helps. If you post how you need to parse the string, there might be different/better ways to go.
Here is the Scenario / requirement
When we submit the DDL to the DBA, DBA implement those DDLs to the database.
=> We need to automate the process of verifying if all the DDL are implemented properly.
1. these DDL statement could be the input string for the Script.
2. Extract the Table name, column name, constraint name etc., from the string and query against the Data dictionaries - USER_TABLES, USER_TAB_COLUMNS, USER_CONSTRAINTS etc.
3. If it matches with the Data dictionary tables then say "Verification Success" else show the difference.
for example:
following are the DDL statement submitted to DBA - (and DBA has already implemented the changes to DB tables)
these are the input string to the script:
Script should parse thr these statement word by word, if first 2 words is ALTER TABLE, pick the table name into a variable(v_tab_name).
if the 4th letter is ADD - pick the 5th word into a variable(v_col_name)
connect to Database and do the following query:
If this query returns one row, then print verification success
Hope this gives a better pic of what I am trying to do.
Last edited by Scott; 08-29-2010 at 06:20 AM..
Reason: Please use code tags
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.
I have no way to actually test this, but it does pass syntax checking by the shell.
Unfortunately I have no data base magic in my head. I don't work with them and that is why I used "database_command" in place of some real db interface. I'm sure there is some 'send-sql' or similar command line interface depending on the database you are using, but I have no experience to even start to point you in the right direction.
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)