[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1423
  • Last Modified:

shell script connect to the database and printing the results

#!/bin/ksh

clientlist=`awk '{print $1}' client_names.txt`
echo "$clientlist\n"
for client in $clientlist
do
results=`isql -w200 -Sservername -Uuser -Ppasswd <<EOF
select ip_address from common.dbo.client_info where environment = 'NON-PROD' and dbName = "$client"
go
EOF
echo "${results}\n";
done

but results are printed something like this

ip_address
-------------
124.100.300.12

ip_address
-------------
123.100.200.12

but i just need the ip address not the headers how could I avoid that?
0
saibsk
Asked:
saibsk
  • 2
1 Solution
 
sentnerCommented:
echo "${results}" | tail +3
0
 
saibskAuthor Commented:
I did something like this

ip_address=`"${results}"|tail +3`;
echo "$ip_address\n";

I need to retreive the ip address and do ssh to that ip address. But gives me this error for the above.

 ip_address      ^J --------------- ^J 10.124.100.205  :  not found


ip_address      ^J --------------- ^J 10.124.101.205  :  not found
 Please advise.
0
 
sentnerCommented:
you'd have to do it like this:

ip_address=`echo "${results}"|tail +3`


0
 
TintinCommented:
You'd be better off changing your SQL query to not print the header.
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now