Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

output in delimeter 1

Status
Not open for further replies.

gatetec

MIS
Mar 22, 2007
420
US
I have this script and like to have the output in a delimiter format (with tab or special character) like below so that I can import the list into Excel w/o reformatting it manually.

Queue Name Device Name Hostname IP Pingble
g3k41p1 hp@g3k41-ps1 g3k41-ps1 10.2.3.129 Pingble
q3k41p9 hp@q3k41-ps9 q3k41-ps9 15.2.3.129 Not-Pingble
….

thx much


for i in `lsallq`
do
echo "Queue Name: " $i
echo "----------------------------------------"
for j in `lsallqdev -q $i`
do
echo " Device Name:" $j
hname=`echo $j | cut -f2 -d"@"`
echo " Hostname :" $hname
ip=`nslookup $hname 2>&1 | awk '/^Address/ {print $2}' | tail -n1`
if ping -c 1 $ip > /dev/null 2>&1; then
echo " IP :" $ip Pingble.
PINGABLE="$PINGABLE $hname[$ip]($i)"
else
echo " IP :" $ip Not Pingble.
UNPINGABLE="$UNPINGABLE $hname[$ip]($i)"
fi
echo ""
done

echo ""
done
 
If your shell support it you may play with the printf command.
An other way is to use awk.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
What does the data look like the file, before you parse it?
 
it is pulling the data with
lsallq and lsallqdev -qxxx commands in AIX.
So, it gets whatever the commands return.
 
What about simply this ?
Code:
echo "Queue Name\tDevice Name\tHostname\tIP\tPingble"
for i in `lsallq`
do
    QN=$i
    for j in `lsallqdev -q $i`
    do
        DN=$j
        hname=`echo $j | cut -f2 -d"@"`
        ip=`nslookup $hname 2>&1 | awk '/^Address/ {print $2}' | tail -n1`
        if ping -c 1 $ip > /dev/null 2>&1; then
            P=Pingble
        else
            P=Not-Pingble
        fi
        echo "$QN\t$DN\t$hname\t$ip\t$P"
    done
done

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That is sweet!!!

I see that some invalid queues are returning.
I like to exclude if the result contains certain IP addresses (i.e. 10.30.8.110). How do you do that?

thx much
 
I see that some invalid queues are returning.
Didn't your posted script have the same behaviour ?
You may replace this:
for j in `lsallqdev -q $i`
with this:
for j in `lsallqdev -q $i 2>/dev/null`

exclude if the result contains certain IP addresses (i.e. 10.30.8.110)
Add the following before the ping line:
[ "$ip" = "10.30.8.110" ] && continue

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Do you mean this?
....

ip=`nslookup $hname 2>&1 | awk '/^Address/ {print $2}' | tail -n1`
[ "$ip" = "10.30.8.110" ] && continue
if ping -c 1 $ip > /dev/null 2>&1; then
P=Pingble
else
P=Not-Pingble
fi
....

I think I am not putting it in the right line....


thx much
 
I think I am not putting it in the right line
Why do you think that ?
 
It is still returing the results with 10.30.8.110 IP.

thx much
 
What is the exact text displayed when you add the following line before the ping ?
Code:
echo "ip='$ip'"
 
PHV,

[ "$ip" = "10.30.8.110" ] filter works well.
and, I like to make to put the loic in IF.

The printer queues with 10.30.8.110 are excluded, which I have to find out the queues excluded.

So, if I print the queues with 10.30.8.110 as "IP UNKNOWN with 10.30.8.110", that will wonderful.

In that case, I can have three categpries, "Pingable", "Not-Pingble", and "IP UNKNOWN with 10.30.8.110".

Pls let me know.

thx much

echo "Queue Name\tDevice Name\tHostname\tIP\tPingble"
for i in `lsallq`
do
QN=$i
for j in `lsallqdev -q $i`
do
DN=$j
hname=`echo $j | cut -f2 -d"@"`
ip=`nslookup $hname 2>&1 | awk '/^Address/ {print $2}' | tail -n1`
if ping -c 1 $ip > /dev/null 2>&1; then
P=Pingble
else
P=Not-Pingble
fi
echo "$QN\t$DN\t$hname\t$ip\t$P"
done
done
 
Like this ?
...
if [ "$ip" = "10.30.8.110" ]; then
P="IP UNKNOWN with $ip"
elif ping -c 1 $ip > /dev/null 2>&1; then
P=Pingble
else
P=Not-Pingble
fi
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top