Unix Korn Shell script on Solaris to DB2 UDB LUW database


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix Korn Shell script on Solaris to DB2 UDB LUW database
# 1  
Old 05-13-2010
Bug Unix Korn Shell script on Solaris to DB2 UDB LUW database

I am rather new to korn shell scripting and attempting to write a Unix script that would detach, attach a range partition table in DB2 UDB LUW database. This would be a job scheduled in control M that reads in an input file with 5 parameters passed to it from the application. I don't have much Unix scripting experience (I am a DB2 UDB LUW DBA) and looking for some direction and possibly sample scripts to see how this could be accomplished
# 2  
Old 05-14-2010
If you ask questions it is always a good idea to provide some sample data as example for what you have and what you want to achieve. Otherwise it is difficult to suggest.

If i get you correctly you have a file (?) with five parameters stated in it (?) and your script is called, has to open the file and retrieve the parameters from it, yes?

Ok, i don't know your file format, but let's suppose its name is "/path/to/param.file" and it looks like that:

Code:
param1="some-value-1"
param2="some-value-2"
param3="some-value-3"
param4="some-value-4"
param5="some-value-5"

Further i suppose that the five parameters are fixed and you know in advance which parameters to expect (the values could differ, but the parameters names do not). Your script could look like this:

Code:
#! /bin/ksh

# .... set some environment first, whatever is needed here ....

typeset  fParam="/path/to/param.file"
typeset  chLineBuffer=""

typeset  achParm[1]=""
typeset  achParm[2]=""
typeset  achParm[3]=""
typeset  achParm[4]=""
typeset  achParm[5]=""

typeset -i iCnt=0
typeset -i lError=0

# read the file (cat), strip all empty lines and comments (sed) and feed the rest to
# the while-loop. There the "case..esac" decides which parameter it is and
# stores it to the appropriate variable. If the parameter is not known an error
# is issued and the script terminates with errorlevel 1.

cat "$fParam" |\
sed 's/^[<spc><tab>]*$//; s/#.*$//' |\
while read chLineBuffer ; do
     case "${chLineBuffer%%=*}" in
          param1)
               achParm[1]="${chLineBuffer##*=}
               ;;

          param2)
               achParm[2]="${chLineBuffer##*=}
               ;;

          param3)
               achParm[3]="${chLineBuffer##*=}
               ;;

          param4)
               achParm[4]="${chLineBuffer##*=}
               ;;

          param5)
               achParm[5]="${chLineBuffer##*=}
               ;;

          *)
               print - "ERROR: unknown parameter $chLineBuffer"
               exit 1
               ;;
     esac
done

# The following part is only necessary if you need to make sure that all five
# parameters are passed. If it is legal to have one or more ommitted you do
# not need this.

iCnt=1
lError=0
while [ $iCnt -le 5 ] ; do
     if [ -z "${achParm[$iCnt]}" ] ; then
          print - "ERROR: no Value for achParm[$iCnt]"
          lError=1
     fi
done
if [ $lError -gt 0 ] ; then
     exit 2
fi

# Put the part which works with the gotten parameters here, for example:

some-command -a "${achParm[1]}" -b "${achParm[2]}" -c "${achParm[3]}"

exit $?

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

[Solved] How to connect DB2 from UNIX shell script?

Hi all, I have a requirement to connect DB2 database and do some operations and generate a report through shell script. Can anyone please tell me how can i connect DB2 from unix shell script? Thanks in ADV. (2 Replies)
Discussion started by: gani_85
2 Replies

2. Shell Programming and Scripting

how do i execute nohup and background job inside the korn script for db2

load_cursor_stmt() { ls /db/admin/ddl/rmn01000/load_cursor*.sql|while read file do echo "${file}" `nohup db2 -tvf "$file" \&` done }Error: ------- /admin/ddl/rmn01000/load_cursor5.sql /db/admin/ddl/rmn01000/load_cursor6.sql + read file + echo... (3 Replies)
Discussion started by: Hangman2
3 Replies

3. Shell Programming and Scripting

Connect status of db2 in Unix shell script

Hi I am trying to connect to db2 database from Unix shell script (k shell) I need to catch the status of connect whether it is succesful or not. ---------------------------------------------------------- # Read login credentials for db2 tput clear echo "Please enter your Userid:\c"... (3 Replies)
Discussion started by: mKarri
3 Replies

4. Shell Programming and Scripting

How to pass a variable as a parameter to DB2 database from shell script

I need to pass a variable as a parameter from shell script into a DB2 database. var=bhuk_1123_Q_11/22/09 select * from tbl1 where serial_id='$var'; I have tried executing it using db2 -tvf scriptname Somebody please help me out with this. It is throwing an error. Please tell me how... (2 Replies)
Discussion started by: ss3944
2 Replies

5. Programming

Acceessing DB2 UDB in AIX COBOL on unix

Hi , We are migrating our database from DB2 z/os to DB2 UDB on UNIX. and cobol on mainframes to AIX cobol on UNIX. We have some cobol Db2 programs that are accessing different Databases how do we code such type of programs in AIX cobol. Do we need to Establish connection for accessing... (0 Replies)
Discussion started by: nal.satish
0 Replies

6. AIX

Ibm db2 udb

Am trying to export the content of Stored Procedure to a file using GET ROUTINE command. After executing the command first few lines of the file contains ASCII characters though i have original text following that. Any help is appreciated. (0 Replies)
Discussion started by: mvictorvijayan
0 Replies

7. AIX

IBM DB2 UDB to SQL Server 2005 Porting

Hi All, Am porting my application from AIX to Windows. As a part of this I need to port the Database in IBM DB2 UDB to SQL Server 2005. Is there any Guide/Doc/Article available on this? How to convert the stored procedures and physical data from DB2 to SQL Server 2005? Thanks in Advance (0 Replies)
Discussion started by: mvictorvijayan
0 Replies

8. Shell Programming and Scripting

Connecting and Querying DB2 database from Unix Script?

I am trying to develop a script that can connect to a DB2 database mainframe and Query the database and display the results. I've been researching, but I have yet to find a definitive solution where I can enter in the Mainframe DB2 address db2:// and query the database and return the results. If... (2 Replies)
Discussion started by: developncode
2 Replies

9. Shell Programming and Scripting

How to connect to database db2 through Unix Shell Script

I am trying to connect to database db2 through shell script. The process I am trying is > db2 It gives me error Access Denied. While checking for access I have the rights. Is there ant other way round..? Please help. (3 Replies)
Discussion started by: ankitgupta
3 Replies

10. Shell Programming and Scripting

Connect to sybase database using Korn shell script

Hi, Can anyone please give me a script or let me know how to connect to a sybase database and execute a query using Korn shell scripts.Am new to Unix but i need to do this ASAP. Please help. Thanks, Gops (7 Replies)
Discussion started by: bhgopi
7 Replies
Login or Register to Ask a Question