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) . > /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][] "80 EE 73 2F 0B 40 "
atPhysAddress[10][] "38 EA A7 6D 2E 8E "
atPhysAddress[10][] "BC 51 FE 50 16 F8 "
atPhysAddress[10][] "00 06 53 FE 39 E0 "
atPhysAddress[10][] "00 18 BA 51 5B 41 "

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

  • 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

first create mysql database: databasename

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


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';
  • 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 = '', 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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