LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-12-2013, 05:44 PM   #1
xenner
Member
 
Registered: Jul 2009
Location: Brisbane
Distribution: RHEL 6.5
Posts: 39

Rep: Reputation: 0
Shell Scripting SNMP walks and populating files


Hi,

So, I would generally go through and discover this myself, but unfortunately, time is of the essence and I am now turning to the community to assist me.. Please help, and I will love you forever!! (Not really, cos I don't actually know you, and that would be weird.)

So, I've been asked to do some nagios config, which I don't have a problem with.. Then, I was given a list of 1000 items to monitor.. Fine, I've done that, and now I have 1000 different cfg files...
Now, I've been given different variables for each item which will be unique to each device I'm monitoring... That's when my brain decided that being awake all night with a baby, and coming to work with little to no sleep was all too much, and it's turning off.

Can someone please give me some guidance, (And speak slowly with explanations) with the following task, it should be simple.

I need to run
snmpwalk -v2c -cfctmonitor 10.x.x.x 1.3.6.1.2.1.2.2.1.2

This should give me some Interface names.. In this case, I would grep out IF-MIB::ifDescr.4 = STRING: ATM0/0/0 AND IF-MIB::ifDescr.8 = STRING: ATM0/0/0.0-aal5 layer

Then, depending if this actually came back with the results I want (So, an 'if' statement), then I'd like to run the next snmpwalk, this time against: 1.3.6.1.2.1.2.2.1.8."x" (x=whatever output the above turned up (the 4 and the 8 from the previous statement, as they held the correct strings).

Then, I need to determine the speed of these interaces using the OID of... 1.3.6.1.2.1.2.2.1.2.4."x" (Where x = the 4 and 8 as previously discovered). Then, from all of those details I got, I need to add them into all the config files that turn up this response.

So basically, I would begin all of this by determining the IP address from each file and running the walks against those ips in a sequential order.
ip_address = for i in $(cat router_list.txt) ;do grep address "$i" |awk '{print $2}' ;done
---- Router_list.txt has a list of all files in the directory----

please help me, you guys are awesome, and no doubt you've already done something similar.

Thanks!!!
 
Old 03-12-2013, 07:33 PM   #2
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,479
Blog Entries: 6

Rep: Reputation: Disabled
Quote:
Originally Posted by xenner View Post
snmpwalk -v2c -cfctmonitor 10.x.x.x 1.3.6.1.2.1.2.2.1.2

This should give me some Interface names.. In this case, I would grep out IF-MIB::ifDescr.4 = STRING: ATM0/0/0 AND IF-MIB::ifDescr.8 = STRING: ATM0/0/0.0-aal5 layer

Then, depending if this actually came back with the results I want (So, an 'if' statement), then I'd like to run the next snmpwalk, this time against: 1.3.6.1.2.1.2.2.1.8."x" (x=whatever output the above turned up (the 4 and the 8 from the previous statement, as they held the correct strings).

Then, I need to determine the speed of these interaces using the OID of... 1.3.6.1.2.1.2.2.1.2.4."x" (Where x = the 4 and 8 as previously discovered). Then, from all of those details I got, I need to add them into all the config files that turn up this response.

So basically, I would begin all of this by determining the IP address from each file and running the walks against those ips in a sequential order.
ip_address = for i in $(cat router_list.txt) ;do grep address "$i" |awk '{print $2}' ;done
---- Router_list.txt has a list of all files in the directory----

please help me, you guys are awesome, and no doubt you've already done something similar.

Thanks!!!
You need a loop script to hit an snmp-enabled router? I could go on for days, but it is not clear to me what your actual request is.
It sounds like you have all the right parts to make this work but perhaps are unsure how to proceed?

Please let us know...

Subscribed with interest...

Nagios - Grrr. Arg...
 
Old 03-12-2013, 07:42 PM   #3
xenner
Member
 
Registered: Jul 2009
Location: Brisbane
Distribution: RHEL 6.5
Posts: 39

Original Poster
Rep: Reputation: 0
You're right on!!! I don't know how to proceed... I have an idea, but that's it

So, I have 1000 routers to get their ID's off.

I have 1000 .cfg files with the ip address's listed of each router.

I just don't know how to go through all the files in one swoop, and assigning the particular OID check against the ones that work, and different OID's to the ones that don't work (Runninga defferent script using an "If OID is != to 'blah'; then do <x>) (As we have multiple router types here and the Network guy refuses to give me the OID's for each router.. Grrrr, leaving me to find them myself).


How many brackets can we have?

Does that explanation help a little.../? Perhaps?

Thank you for your assistance.
 
Old 03-12-2013, 08:27 PM   #4
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,479
Blog Entries: 6

Rep: Reputation: Disabled
Quote:
Originally Posted by xenner View Post
You're right on!!! I don't know how to proceed... I have an idea, but that's it

So, I have 1000 routers to get their ID's off.

I have 1000 .cfg files with the ip address's listed of each router.

I just don't know how to go through all the files in one swoop, and assigning the particular OID check against the ones that work, and different OID's to the ones that don't work (Runninga defferent script using an "If OID is != to 'blah'; then do <x>) (As we have multiple router types here and the Network guy refuses to give me the OID's for each router.. Grrrr, leaving me to find them myself).

How many brackets can we have?

Does that explanation help a little.../? Perhaps?

Thank you for your assistance.
You only need the list of IPs to run smpwalk against.
get those, 1 per line from the 1000 .cfg files and into your home directory as hosts.ips

Code:
for i in $(echo 4 8) ; do snmpwalk -v2c -cfctmonitor $(cat ~/hosts.ips) ifSpeed.$i ; done
should do something, I hope.
If it works, great, if not, well, I'll look at it some more, or someone smarter than I will toss in a solution. You are not that far away from
giving an evil grin at the "Network guy". Bwhaahahahaha

Last edited by Habitual; 03-12-2013 at 09:09 PM. Reason: removed backticks for $(sub_process)
 
1 members found this post helpful.
  


Reply

Tags
bash, bash scripting, scripting, snmp


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash Shell Scripting rename files pomico Programming 9 07-02-2012 01:32 PM
Reading files in shell scripting barunparichha Linux - Software 17 10-26-2010 05:18 AM
shell-scripting.pdf files garethsays Linux - Newbie 2 01-30-2009 06:51 AM
Combine files using shell scripting ccray Linux - Newbie 14 01-12-2006 11:14 AM
Shell Scripting and Files With Spaces Matir Programming 12 08-17-2005 01:43 AM


All times are GMT -5. The time now is 01:07 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration