• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1437
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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