Problem using iSQL and variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem using iSQL and variables
# 1  
Old 10-17-2012
Problem using iSQL and variables

I have searched the forums and other sites and cannot come with the applicable approach for what I am trying to do. I am trying to setup a cron job that executes this script. The script uses iSQL - which is connecting ok - to then query a field and then assign that field to a variable to do an If statement on.

I have tried various different isql statement combinations and cannot get it to work right. The data being returned is the headers and the data. I need the $server variable to equal one string such as "data1" or "data2", which is what is contained in the field from the SELECT statement. Here is the script. Any advice is appreciated!




Code:
#!/bin/bash

server=`isql -v data testacct testpassword <<EOF
set nocount on
USE Servers
select dataserver from systemsettings;
`
If $server = 'data1'
then
ifconfig eth0 192.168.0.20 255.255.255.0
else
ifconfig eth0 192.168.1.20 255.255.255.0
fi

touch /opt/README1.txt


Last edited by Corona688; 10-17-2012 at 08:35 PM..
# 2  
Old 10-17-2012
Can you re-try by disabling column header & command:-

Code:
SET HEADING OFF
SET ECHO OFF

---------- Post updated at 05:39 PM ---------- Previous update was at 05:32 PM ----------

Also try connecting to DB in silent mode -SILENT option.
# 3  
Old 10-17-2012
It looks like it is returning the same result. This is what is being returned:

Code:
returns -1 SQL> select dataserver from systemsettings; +------------------------
---------------------------+ | dataserver | +-----------------------------------
----------------+ | Data1 | +---------------------------------------------------
+ SQLRowCount returns 1 1 rows fetched SQL>


This is what my script looks like now.
------------------------------------------------
Code:
#!/bin/bash

server=`isql -v data testacct testpassword <<EOF
SET HEADING OFF
SET ECHO OFF
set nocount on
USE Servers
select dataserver from systemsettings;
`
echo $server

If $server = 'data1'
then
ifconfig eth0 192.168.0.20 255.255.255.0
else
ifconfig eth0 192.168.1.20 255.255.255.0
fi

touch /opt/README1.txt

------------------------------------------------------


Would you change my script at all? I'm not sure this is the right approach to going about this, but I haven't been able to get anything solid working. I appreciate it!

Last edited by Corona688; 10-17-2012 at 08:35 PM..
# 4  
Old 10-17-2012
Can you remove -v (verbose) option and try?
# 5  
Old 10-18-2012
I tried that and it had no impact on the output.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with variables in sed

Hello! I have a problem to insert variables with sed... And I can't find the solution. :confused: I would like to display one/few line(s) between 2 values. This line works well sed -n '/Dec 12 10:42/,/Dec 12 10:47/p' Thoses lines with variables doesn't work and I don't find the... (2 Replies)
Discussion started by: Castelior
2 Replies

2. Shell Programming and Scripting

concatenate variables problem

Hello, I have a tricky problem: I have a $file with a variable number of occurrences of "ORA-" (in this case two) .......... EXP-00008: ORACLE error 3113 encountered ORA-03113: end-of-file on communication channel EXP-00056: ORACLE error 1403 encountered ORA-01403: no data found... (9 Replies)
Discussion started by: Laurentiu
9 Replies

3. Shell Programming and Scripting

Problem combining two variables into one

Hello, I have a problem combining two variables into one. I did the following: in my env variables i had set PATH_DESTINATION_1=/root/path_one PATH_DESTINATION_2=/root/path_two #!/usr/bin/ksh count=1 count_path=2 while do (3 Replies)
Discussion started by: Eraser
3 Replies

4. Shell Programming and Scripting

Sed with variables problem

I am writing a script with a sed call that needs to use a variable and still have quotations be present in the substitution. Example: sed -i "s/Replacable.\+$/Replaced="root@$VAR"/g" this outputs: where $VAR = place Replaced=root@place and i need Replaced="root@place" ... (2 Replies)
Discussion started by: mcdef
2 Replies

5. Shell Programming and Scripting

Problem with variables in awk

Hi, I've a problem with wariables in awk. My example: $ cat test.txt 12|aaaa 13|bbbb 012|cccc 0123|dddd $ cat test.awk $1 == var {print $0} $ cat test.sh /usr/xpg4/bin/awk -F"|" -v var="012" -f test.awk test.txt (5 Replies)
Discussion started by: apresa
5 Replies

6. Shell Programming and Scripting

Passing Shell Variables in ISQL

Hi.. I am passing a variable in my shell function. I need to access it for an isql comand in the shell script. However the isql o/p gives no results if i pass a variable in the command. The isql command works perfectly fine if i hardcore the table name. My script is : ... (0 Replies)
Discussion started by: dikki
0 Replies

7. UNIX for Advanced & Expert Users

Problem in script when using variables

The AppName may be TCS/HCL/SCB. For All the above 3 i ill have exported TCSDIR/HCLDIR/SCBDIR in .profile with some path. i'm cnstruct the path in script and trying to cd $VARIABLE, it shows "not found". Any solution for this....? > AppName="TCS" > echo $AppName TCS >... (4 Replies)
Discussion started by: palsevlohit_123
4 Replies

8. Solaris

problem with environment variables

hi , i have a problem in setting value of $TERM variable in solaris while installing the SUN SPARCT1 simulation environment on ma pc so some one plkease guide me i have attached a snapshot of my error below thankew (1 Reply)
Discussion started by: Naughtydj
1 Replies

9. UNIX for Advanced & Expert Users

isql/dbisqlc problem

hi.. i have a big problem, and i hope you cand help me. i have a program in unix (program.sc). When i run this program manually works OK (including isql and dbisqlc instructions), but when i execute it from the crontab, it works, but the isql and dbisql instructions don't work. This is the... (1 Reply)
Discussion started by: DebianJ
1 Replies

10. Shell Programming and Scripting

problem with variables

hi all , i wanted to know if someone knows how can i use a variable inside another variable e.g. #!/bin/csh foreach test(1 2 3) set sta_$test = "2" ##now its the problem i want to echo the new var #$sta_$test , each time with anothe num ($test = 1... (2 Replies)
Discussion started by: udi
2 Replies
Login or Register to Ask a Question