DB2 and Unix Variable .....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting DB2 and Unix Variable .....
# 1  
Old 01-08-2008
DB2 and Unix Variable .....

Guys Quick help...

----------------------------
#!/usr/bin/ksh

db2 -x "select count(*) from ${SCHEMA}.EMP"> $HOME/count.dat
COUNT=`cat $HOME/count.dat`
echo Table Count: $COUNT

if ( $COUNT -eq 0 ); then
echo Record Count in Table is 0
exit 1
fi
echo Records Exist
----------------------------



The above script gives error:

Table Count: 0
./test.ksh[8]: 0: not found.
Records Exist



can i get a quick resolution....
# 2  
Old 01-08-2008
Quote:
Originally Posted by freakygs
Guys Quick help...

Code:
#!/usr/bin/ksh

db2 -x "select count(*) from ${SCHEMA}.EMP"> $HOME/count.dat
COUNT=`cat $HOME/count.dat`
echo Table Count: $COUNT

if ( $COUNT -eq 0 ); then
  echo Record Count in Table is 0
  exit 1
fi
echo Records Exist

Use square brackets in your 'if' statement
# 3  
Old 01-08-2008
you can also set the COUNT variable in one step.

Code:
db2 -x "select count(*) from ${SCHEMA}.EMP" | read COUNT

if [[ ${COUNT} -eq 0 ]]; then
   echo "Record Count in Table is 0"
   exit 1
else
   echo "Records Exist"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX with DB2 error status Issue

I have a shell script main.ksh We are calling dbscript.ksh from main.ksh I am using select statement in dbscript.ksh but there is a problem with the select statement in dbscript.ksh but still echo $? is showing as zero. I am using DB2 commands in dbscript.ksh Main.ksh dbscript.ksh echo $? ... (13 Replies)
Discussion started by: vamsi.valiveti
13 Replies

2. UNIX for Dummies Questions & Answers

How to connect to DB2 using UNIX

I am new to Putty, Unix and DB2 and this is what I am working on right now. I installed Putty I got access to username / pwd I got Unix usrname/Pwd.also got the home directory once I login into putty I get the screen and it shows $ sign From here how do I connect to DB2 database? I have... (2 Replies)
Discussion started by: JayDoshi
2 Replies

3. Shell Programming and Scripting

DB2: load command in unix

I am currently trying to load data from e.txt into tablea. I am getting error. db2 connect to qw01p user wcs using abc db2 "LOAD CLIENT FROM /dswork/ECONT/output/interface/e.txt OF DEL MODIFIED BY coldel| SAVECOUNT 0 ROWCOUNT 0 WARNINGCOUNT 0 MESSAGES XTMPRTI1.txt REPLACE into WCSADM.TABLEA... (1 Reply)
Discussion started by: skatpally
1 Replies

4. Shell Programming and Scripting

Help in executing the following db2 sql querry in unix

Hi All, Please help me out in executing the following db2 querry in unix db2 "select AP_RQ_ACQ_INST_ID || ',' || txn_classifier || ',' || AP_RS_RESP_CD || ',' || (count(*) AS COUNT1) || ',' || (SUM(AP_RQ_TXN_AMT) AS TOTAL_AMT) from TXN_RECORD where CREATE_TS > '2010-11-22 11:00:00.008645' ... (1 Reply)
Discussion started by: dudd9
1 Replies

5. Shell Programming and Scripting

Assigning value of a select count(*) from tablename ( run on db2 ) to a unix variable

Hi All, I have browsed through the forums for a similar topic, but there is no topic which explains about this problem, when the backend is DB2. I want to assign the output of a select count(*) from tablename to a unix variable in a shell script. I am using ksh. The database used to... (3 Replies)
Discussion started by: Siddarth
3 Replies

6. 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

7. UNIX for Dummies Questions & Answers

Unable to get the db2 command prompt in unix

Hi, When i try to connect to the db2 database from unix solaris 5.8 version by typing "db2" from the .../sqllib/bin/ folder, i am not getting the db2 command prompt. Could anyone help me resolve this? Here the db2 is executable only. But still iam not getting the db2 prompt. The error i get is... (4 Replies)
Discussion started by: ragavhere
4 Replies

8. Ubuntu

Configure DISPLAY variable for DB2

I am trying to install a DB2 90-day trail but I got the error with the DISPLAY, it says is not configured correctly. I cannot post the error due to I am not in my personal PC but when I type: echo $DISPLAY it shows nothing. I also tried: xclock & and nothing appears just an error. I know there... (2 Replies)
Discussion started by: agasamapetilon
2 Replies

9. Shell Programming and Scripting

need help with UNIX, awk and DB2

Hi i am working on a script which takes a parameter file as input . this parameter file is having SQL statements. I am fetching column names from the output of SQL file using following code: while read Record1 do SQLQuery=`echo $Record1 | awk '{printf $0 }'` ... (2 Replies)
Discussion started by: manmeet
2 Replies

10. Shell Programming and Scripting

connect to Db2 thru Unix

I need to connect to DB2 through Unix and check whether the database is up or not. We are planning to use Neon shadow direct to connect to the same. I would like to know how to pass parameters to neon shadow direct. Any guidance/help in this regard would be helpful. My unix box is AIX 1. ... (3 Replies)
Discussion started by: ranj@tcs
3 Replies
Login or Register to Ask a Question