Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Assign SQL result in shell variable Post 302577007 by matt01 on Monday 28th of November 2011 02:00:23 AM
Old 11-28-2011
Java Assign SQL result in shell variable

Hi

im trying to assign the result of the db2 command to a variable inside a shell script...
: tab_cnt=`db2 "select count(*) from syscat.tables where tabname = 'ABC' and tabschema = 'MATT01'" |head -4|tail +4|cut -c 11`

: echo $tab_cnt

when i echo im getting a blank value.. im expecting value 0...

if i try the same command outside the script
: db2 "select count(*) from syscat.tables where tabname = 'ABC' and tabschema = 'MATT01'" |head -4|tail +4|cut -c 11
: 0 (i get 0... expectd)

I found that if i remove the " |head -4|tail +4|cut -c 11" from the db2 command im getting an output of
tab_cnt=
1
-----------
0

1 record(s) selected.


can smbdy explain why is this happening ..n what can be done for getting the query results in a variable...


thanks in advance...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to assign sql output data to shell script variable

Hi Guys ! I am new to unix and want to find out how we can make sql statement data to shell script variable? Any help/suggestion is greatly appreciated -Chandra (1 Reply)
Discussion started by: kattics
1 Replies

2. Shell Programming and Scripting

assign subst|grep|sed command result to a variable

Hi, I'm quite new to scripting and I want to modify following line of an existing script: MYVAR=`subst |grep 'L:\\\:' | sed -e 's/.*\\\//'`; What I have to do is to use the content of a variable instead of the constant expression 'L:\\\:' as the grep string to be matched. Assuming I already... (5 Replies)
Discussion started by: snowbiker99
5 Replies

3. Shell Programming and Scripting

assign awk command result to a variable

#!/bin/sh # ## MYSTRING = `awk '/myApp.app/' /Users/$USER/Library/Preferences/loginwindow.plist` if then echo String not found defaults write /Users/$USER/Library/Preferences/loginwindow AutoLaunchedApplicationDictionary -dict-add -string Hide -bool YES -string Path -string... (9 Replies)
Discussion started by: dedmakar
9 Replies

4. Shell Programming and Scripting

How to assign the result of a SQL command to more than one variable in shell script.

Hi Friends... Please assist me to assign the result of a SQL query that results two column, to two variables. Pls find the below code that I write for assigning one column to one variable. and please correct if anything wrong.. #! /bin/sh no=' sqlplus -s uname/password@DBname... (4 Replies)
Discussion started by: little_wonder
4 Replies

5. Shell Programming and Scripting

Assign result to variable

Hi friends, firstly, i can run following expression and i took 100 value. sqlplus -s username/password@TTTEST @umt.sql umt.sql exists "select t.deger from parametre t where t.id=30". result of this query =100 i need to assign this value(100) to variable(for example x... (2 Replies)
Discussion started by: temhem
2 Replies

6. Shell Programming and Scripting

How to assign a shell variable to a NUMBER parameter in pl/sql?

I have the below script running for generating file from PL/SQL stored procedure. I need to declare a shell variable and then pass this to sqlplus command to pass the same as a INPUT parameter for the stored procedure. Please help to do this. #!/bin/sh minlimit=0 maxlimit=10 size=100 while... (0 Replies)
Discussion started by: vel4ever
0 Replies

7. Shell Programming and Scripting

Assign the result of a multiline command to a variable

Hi, I have the following command that lists all the .o files from all the directories except of vwin (which I don't want it) for i in `ls -d */*.o|awk '$0 !~ "vwin"'`; do echo $i; done The result is something like that dir1/file1.o dir1/file2.o dir2/file3.o etc. So, I want to create a... (9 Replies)
Discussion started by: scor6800
9 Replies

8. Shell Programming and Scripting

Assign awk gsub result to a variable

Hello, I have searched but failed to find what exactly im looking for, I need to eliminate first "." in a output so i can use something like the following echo "./abc/20141127" | nawk '{gsub("^.","");print}' what i want is to use gsub result later on, how could i achieve it? Let say... (4 Replies)
Discussion started by: EAGL€
4 Replies

9. Shell Programming and Scripting

Assign the return value of the SQL to a variable in UNIX

Hi I am new to UNIX. I am trying the below and getting the error. I am trying to assign the variable with the value of the query result. I want this value to use in the next steps. Created UNIX file (Batch.sh) as below #!/bin/ksh sqlplus callidus/callidus4u@attstcal @Batch.sql ... (2 Replies)
Discussion started by: KrishBalu
2 Replies

10. Shell Programming and Scripting

Remove a character and assign result to a variable

I am reading lines from a file that contain a number sign (#) before a three or four digit number: #1043 #677 I can remove the '#' and get just the number. However, I then want to assign that number to a variable and use it as part of a path further on in my program: /mydir/10/1043 for... (5 Replies)
Discussion started by: KathyB148
5 Replies
FS_NEWCELL(1)						       AFS Command Reference						     FS_NEWCELL(1)

NAME
       fs_newcell - Changes the kernel-resident list of a cell's database servers

SYNOPSIS
       fs newcell -name <cell name> -servers <primary servers>+
	   [-linkedcell <linked cell name>] [-help]

       fs n -n <cell name> -s <primary servers>+
	   [-l <linked cell name>] [-h]

DESCRIPTION
       The fs newcell command removes the Cache Manager's kernel-resident list of database server machines for the cell specified by the -name
       argument and replaces it with the database server machines named by the -servers argument.

       Each time the machine reboots, the Cache Manager constructs the kernel list of cells and database server machines by reading the local
       /etc/openafs/CellServDB file. This command does not change the CellServDB file, so any changes made with it persist only until the next
       reboot, unless the issuer also edits the file. The output of the fs listcells command reflects changes made with this command, because that
       command consults the kernel-resident list rather than the CellServDB file.

       This command can introduce a completely new cell into the kernel-resident list, but cannot make a cell inaccessible (it is not possible to
       remove a cell's entry from the kernel-resident list by providing no values for the -server argument). To make a cell inaccessible, remove
       its entry from the CellServDB file and reboot the machine.

       If the -name argument names a DCE cell, then the -servers argument names DFS Fileset Location (FL) Server machines. The -linkedcell
       argument specifies the name of the AFS cell to link to a DCE cell for the purpose of DFS fileset location.

CAUTIONS
       Some commands, such as the aklog or klog.krb5 commands, work correctly only when the information is accurate for a cell in both the
       CellServDB file and the kernel-resident list.

OPTIONS
       -name <cell name>
	   Specifies the fully-qualified cell name of the AFS or DCE cell.

       -servers <primary servers>+
	   Specifies the fully-qualified hostnames of all AFS database server machines or DFS Fileset Location (FL) Server machines for the cell
	   named by the -name argument. If FL Server machines are specified, the local machine must be running the AFS/DFS Migration Toolkit
	   Protocol Translator.

       -linkedcell <linked cell name>
	   Specifies the name of the AFS cell to link to a DCE cell for the purpose of DFS fileset location.

       -help
	   Prints the online help for this command. All other valid options are ignored.

EXAMPLES
       The following example changes the machine's kernel-resident list of database server machines for the ABC Corporation cell to include the
       machines "db1.abc.com" and "db2.abc.com":

	  % fs newcell -name abc.com -servers db1.abc.com db2.abc.com

       The following example links the DCE cell "dce.abc.com" to the AFS cell "abc.com". The AFS client contacts the Fileset Location (FL) servers
       "db1.dce.abc.com" and "db2.dce.abc.com" for fileset location information as it interprets a DFS pathname.

	  % fs newcell -name dce.abc.com 
	      -servers db1.dce.abc.com db2.dce.abc.com 
	      -linkedcell abc.com

PRIVILEGE REQUIRED
       The issuer must be logged in as the local superuser root.

SEE ALSO
       CellServDB(5), fs_listcells(1)

COPYRIGHT
       IBM Corporation 2000. <http://www.ibm.com/> All Rights Reserved.

       This documentation is covered by the IBM Public License Version 1.0.  It was converted from HTML to POD by software written by Chas
       Williams and Russ Allbery, based on work by Alf Wachsmann and Elizabeth Cassell.

OpenAFS 							    2012-03-26							     FS_NEWCELL(1)
All times are GMT -4. The time now is 10:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy