Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am retreiving arp tables from a switch using snmp. I can poll the tables to a text file, but i want to do it to the mysql db. this is the code i am using to poll to text file

*/5 * * * *  root /usr/bin/snmpbulkwalk -v 2c -c public(assumed community) -OXsq  (ip adress of switch) .1.3.6.1.2.1.3.1.1.2 > /tmp/S01_ARP.txt

How can i modify so that the results are polled to the table arp_tab that i have created in the mysql database The output come out as

atPhysAddress[10][1.172.16.1.5] "80 EE 73 2F 0B 40 "
atPhysAddress[10][1.172.16.1.25] "38 EA A7 6D 2E 8E "
atPhysAddress[10][1.172.16.1.32] "BC 51 FE 50 16 F8 "
atPhysAddress[10][1.172.16.1.200] "00 06 53 FE 39 E0 "
atPhysAddress[10][1.172.16.1.210] "00 18 BA 51 5B 41 "

i would want the ip address and the mac address to be mapped into the database

share|improve this question
1  
Well, you can always write some script that calls snmpbulkwalk and then parses ans stores the result in MySQL. Also I think Cacti does something similar, so you may check its source code. Can you provide an example of the output you get? –  Salem Aug 22 '13 at 12:36
    
i will put the output into the original question –  sosytee Aug 22 '13 at 12:50

2 Answers 2

up vote 1 down vote accepted

first create mysql database: databasename

create mysql table with 2 text fields for IP and MAC:

#!/bin/bash

sed  's/atPhysAddress\[10\]\[//g' arp.txt | sed 's/\]\ \"/\|/g' | sed 's/\ \"/\|/g'> /tmp/arp.new

mysql -uroot -ppassword  databasename <<EOF
load data infile '/tmp/arp.new'
into table tablename
fields terminated by '|'
escaped by '\\\'
lines terminated by '\n';
EOF
share|improve this answer
    
I have accepted it as an answer because it has shown me the process to follow, the code doesnt run though and that will be my homework –  sosytee Aug 23 '13 at 17:38

First, create a database mydatabase, Then, create a table mytable with the fields ip_address, and mac_address. I am assuming you know how to do this. If you don't, specify this.

Try and get your output into a format like the example below :

INSERT INTO mytable SET ip_address = '1.172.16.1.5', mac_address = "80 EE 73 2F 0B 40";

Then input the SQL commands into the mysql database.

mysql mydatabase -u mydatabase_user -p < /tmp/S01_ARP.txt

Supply the database password when prompted.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.