We help IT Professionals succeed at work.

shell script connect to the database and printing the results

saibsk
saibsk asked
on
#!/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?
Comment
Watch Question

Commented:
echo "${results}" | tail +3

Author

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.
Commented:
you'd have to do it like this:

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


CERTIFIED EXPERT
Top Expert 2007

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

Explore More ContentExplore courses, solutions, and other research materials related to this topic.