Help req for...shell script to catch "db2 connect" errors ...


 
Thread Tools Search this Thread
Operating Systems Linux Help req for...shell script to catch "db2 connect" errors ...
# 1  
Old 09-22-2008
Help req for...shell script to catch "db2 connect" errors ...

Hello friends,

Assume that, I am trying to execute a "db2 connect" command from Linux shell prompt via a shell script called "sample"

sample
db2 connect to bas39

$sample

If the database is not present its should display a custom error message by catching the error message given by db2. how to do this using shell script ?.

Probably it will help me to convert error codes to much more meaningful message......help me. thanks. Smilie
# 2  
Old 09-23-2008
Inside sample, put this:
Code:
#!/bin/sh
db2 connect to bas39 2>/tmp/db_error$$
exit_code=$?

while read line ; do
    echo "$line" | grep -q "SOMEERROR" && echo "You got some error there, buster" && continue
    echo "$line" | grep -q "OTHERERR" && echo "Oh not another one!" && continue
    echo "$line" | grep -q "still another error" && echo "Geez this database stinks!" && continue
    # Add as many echo/grep/continues as you need...
done < /tmp/db_error$$
exit $exit_code

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

How to catch errors in a shell script ( multiple commands )?

Hi I have a shell script like that Main() { DAY=$(date +"%d-%m-%Y") TIME=$(date +"%T") Command 1 Command 2 ... Command n } I would like to catch errors from all commands in Main() and write these errors into a file , something likes this: Main if < error > then echo... (3 Replies)
Discussion started by: bobochacha29
3 Replies

3. Shell Programming and Scripting

connect to db2 using shell script

Guys, I am trying to write a shell script that connect to wcsprod database and read the query #!/bin/ksh sqlplus -s < connect to wcsprod user wcsadm using pwd > select * from catentry fetch first 1 row only with ur; databse: wcsprod user: wcsadm pwd: pwd thanks (1 Reply)
Discussion started by: skatpally
1 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

6. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. AIX

"too big" and "not enough memory" errors in shell script

Hi, This is odd, however here goes. There are several shell scripts that run in our production environment AIX 595 LPAR m/c, which has sufficient memory 14GB (physical memory) and horsepower 5CPUs. However from time to time we get the following errors in these shell scripts. The time when these... (11 Replies)
Discussion started by: jerardfjay
11 Replies

8. UNIX for Dummies Questions & Answers

Exception while loading DB2 driver Class.forName("com.ibm.db2.jcc.DB2Driver")

Hi... I m working on UNIX z/OS. Actually i have to pass the parameters from the JCL to java-db2 program thru PARM. I am able to pass the arguments but the problem occured is, it is throwing an exception while loading the db2 driver as 'Javaclassnotfound:com.ibm.db2.jcc.DB2Driver'... (0 Replies)
Discussion started by: Sujatha Gowda
0 Replies

9. HP-UX

Shell Script fails with "can't connect to client"

Hi Unix Gurus, I have written a shell script to unfreeze all frozen media in NetBackup. Here is the script written on HP-UX using ksh: *********************************************** set -x cd $HOME rm -f frozentest rm -f mediaserver cd /usr/openv/netbackup/bin/admincmd pbrun... (2 Replies)
Discussion started by: sseenu79
2 Replies

10. UNIX for Dummies Questions & Answers

No utpmx entry: you must exec "login" from lowest level "shell"

Hi I have installed solaris 10 on an intel machine. Logged in as root. In CDE, i open terminal session, type login alex (normal user account) and password and i get this message No utpmx entry: you must exec "login" from lowest level "shell" :confused: What i want is: open various... (0 Replies)
Discussion started by: peterpan
0 Replies
Login or Register to Ask a Question