awk parse snmp results


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk parse snmp results
# 1  
Old 08-18-2015
awk parse snmp results

i run the command
snmptable -v2c -c public myIP IF-MIB::ifTable
the result look like this :
Code:
SNMP table: IF-MIB::ifTable

 ifIndex                                    ifDescr         ifType ifMtu    ifSpeed    ifPhysAddress ifAdminStatus ifOperStatus 
       1        Unit: 1 Slot: 0 Port: 1 10G - Level ethernetCsmacd  1518 4294967295 f8:b1:56:56:47:4            up           up  
       2        Unit: 1 Slot: 0 Port: 2 10G - Level ethernetCsmacd  1518 4294967295 f8:b1:56:56:47:4            up           up
       3        Unit: 1 Slot: 0 Port: 3 10G - Level ethernetCsmacd  1518 4294967295 f8:b1:56:56:47:4            up           up
       4        Unit: 1 Slot: 0 Port: 4 10G - Level ethernetCsmacd  1518 4294967295 f8:b1:56:56:47:4            up         down
       5        Unit: 1 Slot: 0 Port: 5 10G - Level ethernetCsmacd  1518 4294967295 f8:b1:56:56:47:4            up           up

how can i get a row by the first column certain value (ifIndex), and a certain column in that row?

Last edited by Scrutinizer; 08-18-2015 at 10:06 AM.. Reason: quote tags changed to code tags
# 2  
Old 08-18-2015
As an example, if I want the index of the entries with a status of 'down':
Code:
... | awk '$NF == "down" { print $1; }'

if you want the whole row:
Code:
... | awk '$NF == "down" { print; }'

or:
Code:
... | grep ' down$'

An interface that is not at 10G or is down:
Code:
... | awk '$8 != "10G" || $NF == "down" { print $1; }'

# 3  
Old 08-18-2015
i don't now why, but the awk and the grep is not working for me Smilie
how the awk now's the columns delimiter?
# 4  
Old 08-18-2015
Exactly WHAT is not working for you? Please be detailed and specific, post error msgs or what have you.

And, WHAT do you need? Which pattern should be matched, and which columns should be printed?

awk has a space as the default FS char, and man awk:
Quote:
In the special case that FS is a single space, fields are separated by runs of spaces and/or tabs and/or newlines.
# 5  
Old 08-18-2015
for example i tried to do
Code:
 | awk '$NF == "down" { print; }'

and didnt get any result
# 6  
Old 08-19-2015
First thought: DOS line terminators (<CR><LF>). How was the input file produced? Would $1 == 3 work?

And, you didn't answer the other questions we need answered to help you.
# 7  
Old 08-19-2015
yes this works
Code:
$1 == 3

i am trying to find a structure of the table, so i will be able to get data by column.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

AIX native SNMP producing limited results when walking MIB tree

The company I work for has various AIX servers that I've recently migrated to AIX 7.1 (from 6.1). Some are powerHA clusters some are not. Likewise, the systems engineer that I replaced had net-snmp installed on said clustered systems. Long story short I am re-invoking AIX's native SNMP (v3) for... (1 Reply)
Discussion started by: davix
1 Replies

2. UNIX for Dummies Questions & Answers

Need to transfer all kernel logs (var/log/messages) to the snmp listener as snmp trap

i am working with embedded system -Dell DCS management sub system. my question is as below: currently we are using linux kernel 2.6.30 build and we have a kernel logs stored to the /var/log/messages path. now we have to transfer all this logs to the specified SNMP target as a part of SNMP... (4 Replies)
Discussion started by: vipul_prajapati
4 Replies

3. Shell Programming and Scripting

Substitute from awk results

Hi, The following awk command : asmcmd lsdg | awk '{print $13;}' | grep -i ${SID} return the following output . An Empty line + two lines contain "/" at the end of the line INDEVDATA/ INDEVFRA/ I need to remove the "/" as well as the empty line. Please advise Thanks (3 Replies)
Discussion started by: Yoav
3 Replies

4. Red Hat

Sending data from DELL OMSA SNMP and Custom SNMP MIB to same UDP port 161

Hi , Currently DELL OMSA SNMP sends data through default udp port 161.I want my custom SNMP MIB also to send data in the same udp port 161.Whether its possible.If yes where to configure .I tried starting my custom MIB in udp port 161,but it throws port already in use.Kindly guide. (1 Reply)
Discussion started by: prabakar4all
1 Replies

5. IP Networking

Sending data from DELL OMSA SNMP and Custom SNMP MIB to same UDP port 161

Hi , Currently DELL OMSA SNMP sends data through default udp port 161.I want my custom SNMP MIB also to send data in the same udp port 161.Whether its possible.If yes where to configure .I tried starting my custom MIB in udp port 161,but it throws port already in use.Kindly guide. (0 Replies)
Discussion started by: prabakar4all
0 Replies

6. Shell Programming and Scripting

awk script to parse results from TWO files

I am trying to parse two files and get data that does not match in one of the columns ( column 3 in my case ) Data for two files are as follows A.txt ===== abc 10 5 0 1 16 xyz 16 1 1 0 18 efg 30 8 0 2 40 ijk 22 2 0 1 25 B.txt ===== abc... (6 Replies)
Discussion started by: roger67
6 Replies

7. Shell Programming and Scripting

Parse file using awk and work in awk output

hi guys, i want to parse a file using public function, the file contain raw data in the below format i want to get the output like this to load it to Oracle DB MARWA1,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 MARWA2,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 this the file raw format: Number of... (6 Replies)
Discussion started by: dagigg
6 Replies

8. Shell Programming and Scripting

need a little help with results from awk

Hi there all, I am using a line to get some replys from my PS I do ps -ef |awk '{printf $9}' But my result is 1 big line. No spaces between the lines or someting for example:... (2 Replies)
Discussion started by: draco
2 Replies

9. Shell Programming and Scripting

Shell Script Needed to Parse Results

Raw Results: results|192.168.2|192.168.2.1|general/udp|10287|Security Note|For your information, here is the traceroute from 192.168.2.24 to 192.168.2.1 : \n192.168.2.24\n192.168.2.1\n\n results|192.168.2|192.168.2.1|ssh (22/tcp)|22964|Security Note|An SSH server is running on this port.\n... (2 Replies)
Discussion started by: jroberson
2 Replies

10. Shell Programming and Scripting

AWK - no search results

Hi all, I'm new to awk and I'm experiencing syntax error that I don't know how to resolve. Hopefully some experts in this forum can help me out. I created an awk file that look like this: $ cat myawk.awk BEGIN { VAR1=PATTERN1 VAR2=PATTERN2 } /VAR1/ { flag=1 } /VAR2/ { flag=0 } {... (7 Replies)
Discussion started by: hk18
7 Replies
Login or Register to Ask a Question