ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Greetings all,
I have a working code that goes through my entire Network (192.168.0.0/16) and do an snmpget specific OID on certain devices.
This script currently takes about 4 hours to run.
I was wondering where I should make changes to make it faster or should I look at moving the script to Perl( I read something about spwan, but not sure what that is)
Code:
#!/bin/bash
#
COUNT=10
# bash while loop
while [ $COUNT -lt 230 ]; do
y=2
while [ $y -lt 200 ]; do
#Get IPAddress, SystemDesc, DeviceType
snmpget -v 1 -Ovq -r 0 -c public 192.168.$COUNT.$y .1.3.6.1.2.1.4.20.1.1.192.168.$COUNT.$y .1.3.6.1.2.1.1.1.0 .1.3.6.1.4.1.318.1.4.2.2.1.2.1 | sed -n '1h;2,$H;${g;s/\n/,/g;p}' >> 192.168.xls
let y=y+1
done
let COUNT=COUNT+1
done
#!/bin/bash
#
COUNT=10
# bash while loop
while [ $COUNT -lt 230 ]; do
y=2
while [ $y -lt 200 ]; do
#Get IPAddress, SystemDesc, DeviceType
snmpget -v 1 -Ovq -r 0 -c public 192.168.$COUNT.$y .1.3.6.1.2.1.4.20.1.1.192.168.$COUNT.$y .1.3.6.1.2.1.1.1.0 .1.3.6.1.4.1.318.1.4.2.2.1.2.1 | sed -n '1h;2,$H;${g;s/\n/,/g;p}' >> 192.168.xls
let y=y+1
done
let COUNT=COUNT+1
done
Thanks in advance,
SeeFor
Code:
#!/bin/bash
for (( a=10; a<230; a++ )); do
for (( b=2; b<200; b++ )); do
snmpget -v 1 -Ovq -r 0 -c public 192.168.$a.$b .1.3.6.1.2.1.4.20.1.1.192.168.$a.$b .1.3.6.1.2.1.1.1.0 .1.3.6.1.4.1.318.1.4.2.2.1.2.1 | sed -n '1h;2,$H;${g;s/\n/,/g;p}' >> 192.168.xls
done
done
Should do the same thing with less code, although I think there are better options to do this, like for instance generating a list of which of these devices actually exist via nmap and using the output nmap generates to determine which devices you need to poll. etc.
Another solution would be to make an nmap script that walks the oid and just use that.
The problem is that we are always adding more devices to the network and most of the times we have devices with misconfiguration on them (Wrong IP, Device Name, etc)
So I try to can the entire network looking for the devices.
The problem is that we are always adding more devices to the network and most of the times we have devices with misconfiguration on them (Wrong IP, Device Name, etc)
So I try to can the entire network looking for the devices.
Thanks again,
SeeFor
I think an nmap script may be your best option in that case.
You also definitely want to be able to focus that script upon particular sub-networks.
Is there no way to arrange for "every device please report-in?" Something like the nagios open-source package allows? In other words, instead of combing the world looking for lost sheep, just to find out if any are actually lost, then have all the sheep report-in from time to time. If one sheep fails to report, then you can go to that box, pick it up in your hand, and find out why it isn't answering. Likewise, if it reports-in incorrectly, you can put your grubby fingers on it and find out what's wrong.
And if you don't (use | know about) nagios... make it your business to do so.
Again many thanks for the replies, I will look into both nmap and nagios
Thanks,
SeeFor
I agree that nagios is also a better solution for what you're looking to do, but if you want to do the 'search for lost sheep' method, look at making a script in nmap.
Nagios won't work for these Devices, cause I'm trying to retrieve the devices configuration. Nagios will work great from some smarter devices in out network.
nmap looks like a great solution, but I can't find much on the scripting so far I found this:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.