- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- AWK Help Needed
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 11:20 AM
12-05-2007 11:20 AM
I am trying do a small script that will do linkloop tests on interfaces, and I need your help.
Here is a sample output of just a bare lanscan (minus a few interfaces):
lanscan
Hardware Station Crd Hdw Net-Interface NM MAC HP-DLPI DLPI
Path Address In# State NamePPA ID Type Support Mjr#
0/5/1/0/4/0 0x001A4BF56734 2 UP lan2 snap2 1 ETHER Yes 119
0/5/1/0/4/1 0x001A4BF56735 3 UP lan3 snap3 2 ETHER Yes 119
I thought I was on to something when I was able to get the following formated output:
# lanscan | grep -v Hardware | grep -v Path | awk '{print $3, $2}'
2 0x001A4BF56734
3 0x001A4BF56735
4 0x001A4BF56736
5 0x001A4BF56737
6 0x001A4BF56394
7 0x001A4BF56395
8 0x001A4BF56396
9 0x001A4BF56397
0 0x001A4B0766B6
1 0x001A4B0766B7
And then I put the output into a for loop, and it falls apart:
for i in `lanscan | grep -v Hardware | grep -v Path | awk '{print $3, $2}'`
do
echo linkloop $i
done
linkloop 2
linkloop 0x001A4BF56734
linkloop 3
linkloop 0x001A4BF56735
linkloop 4
linkloop 0x001A4BF56736
linkloop 5
linkloop 0x001A4BF56737
linkloop 6
linkloop 0x001A4BF56394
linkloop 7
linkloop 0x001A4BF56395
linkloop 8
linkloop 0x001A4BF56396
linkloop 9
linkloop 0x001A4BF56397
linkloop 0
linkloop 0x001A4B0766B6
linkloop 1
linkloop 0x001A4B0766B7
Please help.
Solved! Go to Solution.
- Tags:
- lanscan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 11:25 AM
12-05-2007 11:25 AM
Re: AWK Help Needed
Try this:
for INT in $(lanscan | grep -v -e Hardware -e Path | awk '{print $3}')
do
echo linkloop ${INT}
done
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 11:26 AM
12-05-2007 11:26 AM
Re: AWK Help Needed
for i in `netstat -in|grep -vE "lo0|Name|lan[0-9*]:"|awk '{print substr($0,4,6)}'`
do
echo $i | grep -q 90[0-9]
if [[ $? -eq 0 ]]; then
for j in `lanscan -q | grep $i`
do
linkloop -i $i `yes|lanadmin -g $j | grep "Station Address" | awk '{print $4}'` 2>&1 | grep -q "OK" && echo "lan$j is OK" || echo "lan$j is NOT OK"
done
else
linkloop -i $i `lanadmin -g $i | grep "Station Address" | awk '{print $4}'` 2>&1 | grep -q "OK" && echo "lan$i is OK" || echo "lan$i is NOT OK"
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 11:31 AM
12-05-2007 11:31 AM
Re: AWK Help Needed
This:
for i in `lanscan | grep -v Hardware | grep -v Path | awk '{print $3, $2}'`
do
echo linkloop $i
done
linkloop 2
linkloop 0x001A4BF56734
linkloop 3
linkloop 0x001A4BF56735
linkloop 4
linkloop 0x001A4BF56736
linkloop 5
linkloop 0x001A4BF56737
linkloop 6
linkloop 0x001A4BF56394
linkloop 7
linkloop 0x001A4BF56395
linkloop 8
linkloop 0x001A4BF56396
linkloop 9
linkloop 0x001A4BF56397
linkloop 0
linkloop 0x001A4B0766B6
linkloop 1
linkloop 0x001A4B0766B7
Should be:
for i in `lanscan | grep -v Hardware | grep -v Path | awk '{print $3, $2}'`
do
echo linkloop -i $i
done
linkloop -i 2
linkloop -i 0x001A4BF56734
linkloop -i 3
linkloop -i 0x001A4BF56735
linkloop -i 4
linkloop -i 0x001A4BF56736
linkloop -i 5
linkloop -i 0x001A4BF56737
linkloop -i 6
linkloop -i 0x001A4BF56394
linkloop -i 7
linkloop -i 0x001A4BF56395
linkloop -i 8
linkloop -i 0x001A4BF56396
linkloop -i 9
linkloop -i 0x001A4BF56397
linkloop -i 0
linkloop -i 0x001A4B0766B6
linkloop -i 1
linkloop -i 0x001A4B0766B7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 11:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 11:44 AM
12-05-2007 11:44 AM
Re: AWK Help Needed
lanscan | awk '/[0-9]/{print $3, $2}' | while read i
do
linkloop -i $i
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 11:51 AM
12-05-2007 11:51 AM
Re: AWK Help Needed
Perhaps:
#!/usr/bin/sh
LANS=$(lanscan | awk '!/Hardware|Path/ {print $3":"$2}' )
for LAN in ${LANS}
do
LNBR=$(echo ${LAN} | cut -d: -f1)
echo "LAN #${LNBR}"
LINK=$(echo ${LAN} | cut -d: -f2)
linkloop ${LINK}
done
...The most important point is NOT to use 'grep' whwn 'awk' is designed to pattern match. Avoid the useless, extra process!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 11:55 AM
12-05-2007 11:55 AM
Re: AWK Help Needed
lanscan | awk '/[0-9]/{print $3, $2}' | while read i
do
echo linkloop -i $i
echo "----------------------"
linkloop -i $i
echo
done
The output:
linkloop -i 0 0x00306E13F682
----------------------
Link connectivity to LAN station: 0x00306E13F682
error: expected primitive 0x30, got DL_ERROR_ACK
dl_error_primitive = 0x2d
dl_errno = 0x04
dl_unix_errno = 57
error - did not receive data part of message
linkloop -i 2 0x00306E0C541F
----------------------
Link connectivity to LAN station: 0x00306E0C541F
-- OK
linkloop -i 3 0x00306E38D363
----------------------
Link connectivity to LAN station: 0x00306E38D363
-- OK
linkloop -i 1 0x00306E21D5B7
----------------------
Link connectivity to LAN station: 0x00306E21D5B7
-- OK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 12:04 PM
12-05-2007 12:04 PM
Re: AWK Help Needed
do
echo linkloop -i $i
echo "----------------------"
linkloop -i $i
echo
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 12:26 PM
12-05-2007 12:26 PM
Re: AWK Help Needed
lanscan | awk '/[0-9]/{print $3, $2}' | while read i
do
echo LAN `echo $i | awk '{print $1}'`
echo linkloop -i $i
echo "----------------------"
linkloop -i $i
echo
done
Output:
LAN 0
linkloop -i 0 0x00306E13F682
----------------------
Link connectivity to LAN station: 0x00306E13F682
error: expected primitive 0x30, got DL_ERROR_ACK
dl_error_primitive = 0x2d
dl_errno = 0x04
dl_unix_errno = 57
error - did not receive data part of message
LAN 2
linkloop -i 2 0x00306E0C541F
----------------------
Link connectivity to LAN station: 0x00306E0C541F
-- OK
LAN 3
linkloop -i 3 0x00306E38D363
----------------------
Link connectivity to LAN station: 0x00306E38D363
-- OK
LAN 1
linkloop -i 1 0x00306E21D5B7
----------------------
Link connectivity to LAN station: 0x00306E21D5B7
-- OK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 12:47 PM
12-05-2007 12:47 PM
Re: AWK Help Needed
Think optimization and reduce this to one 'awk' process:
# cat ./mylans
#!/usr/bin/sh
LANS=$(lanscan | awk 'NR>2 {print $3":"$2}' )
for LAN in ${LANS}
do
LNBR=${LAN%%:*}
LINK=${LAN##*:}
echo "\nlinkloop -i ${LNBR} ${LINK}\n----------------------"
linkloop ${LINK}
done
# ./mylans
linkloop -i 0 0x080009D97070
----------------------
Link connectivity to LAN station: 0x080009D97070
-- OK
linkloop -i 1 0x0060B083C26C
----------------------
Link connectivity to LAN station: 0x0060B083C26C
error: get_msg2 getmsg failed, errno = 4
-- FAILED
frames sent : 1
frames received correctly : 0
reads that timed out
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 01:42 PM
12-05-2007 01:42 PM
Re: AWK Help Needed
Whenever I run your script on my server, there are no lan interfaces that come back ok. I get the following:
root@server:/> cat linkloop_test1
#!/usr/bin/sh
LANS=$(lanscan | awk 'NR>2 {print $3":"$2}' )
for LAN in ${LANS}
do
LNBR=${LAN%%:*}
LINK=${LAN##*:}
echo "\nlinkloop -i ${LNBR} ${LINK}\n----------------------"
linkloop ${LINK}
done
root@server:> sh linkloop_test1
linkloop -i 0 0x00306E13F682
----------------------
Link connectivity to LAN station: 0x00306E13F682
error: expected primitive 0x30, got DL_ERROR_ACK
dl_error_primitive = 0x2d
dl_errno = 0x04
dl_unix_errno = 57
error - did not receive data part of message
linkloop -i 2 0x00306E0C541F
----------------------
Link connectivity to LAN station: 0x00306E0C541F
error: expected primitive 0x30, got DL_ERROR_ACK
dl_error_primitive = 0x2d
dl_errno = 0x04
dl_unix_errno = 57
error - did not receive data part of message
linkloop -i 3 0x00306E38D363
----------------------
Link connectivity to LAN station: 0x00306E38D363
error: expected primitive 0x30, got DL_ERROR_ACK
dl_error_primitive = 0x2d
dl_errno = 0x04
dl_unix_errno = 57
error - did not receive data part of message
linkloop -i 1 0x00306E21D5B7
----------------------
Link connectivity to LAN station: 0x00306E21D5B7
error: expected primitive 0x30, got DL_ERROR_ACK
dl_error_primitive = 0x2d
dl_errno = 0x04
dl_unix_errno = 57
error - did not receive data part of message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 02:22 PM
12-05-2007 02:22 PM
Re: AWK Help Needed
> Whenever I run your script on my server, there are no lan interfaces that come back ok.
Ah, my apologies. The manpages note that "-i PPA ...If this option is omitted, linkloop uses the first PPA it encounters in an internal data structure."
Frankly, I missed that and would need to change:
# linkloop ${LINK}
...to:
# linkloop -i ${LNBR} ${LINK}
...thus:
# cat ./mylans
#!/usr/bin/sh
LANS=$(lanscan | awk 'NR>2 {print $3":"$2}' )
for LAN in ${LANS}
do
LNBR=${LAN%%:*}
LINK=${LAN##*:}
echo "\nLAN ${LNBR}\nlinkloop -i ${LNBR} ${LINK}\n----------------------"
linkloop -i ${LNBR} ${LINK}
done
...BUT, this could be done without parameter substitution in the first place using a read (thinking as Sandman showed):
# cat ./mylans2
#!/usr/bin/sh
lanscan | awk 'NR>2 {print $3,$2}' | \
while read LNBR LINK
do
echo "\nLAN ${LNBR}\nlinkloop -i ${LNBR} ${LINK}\n----------------------"
linkloop -i ${LNBR} ${LINK}
done
...
If nothing else, we let the shell do most of our work and spawn as absolutely few processes as necessary.
Regards!
...JRF...