LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-27-2009, 03:55 PM   #1
seefor
Member
 
Registered: Mar 2006
Posts: 34

Rep: Reputation: 15
Question Making a Shell Script better


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
Thanks in advance,
SeeFor
 
Old 02-27-2009, 04:23 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 163Reputation: 163
Quote:
Originally Posted by seefor View Post
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
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.

Last edited by rweaver; 02-27-2009 at 04:27 PM.
 
Old 02-27-2009, 05:43 PM   #3
seefor
Member
 
Registered: Mar 2006
Posts: 34

Original Poster
Rep: Reputation: 15
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
 
Old 03-02-2009, 09:46 AM   #4
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 163Reputation: 163
Quote:
Originally Posted by seefor View Post
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.
 
Old 03-02-2009, 11:11 AM   #5
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,425

Rep: Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159
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.
 
Old 03-02-2009, 01:18 PM   #6
seefor
Member
 
Registered: Mar 2006
Posts: 34

Original Poster
Rep: Reputation: 15
Again many thanks for the replies, I will look into both nmap and nagios

Thanks,
SeeFor
 
Old 03-02-2009, 01:40 PM   #7
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 163Reputation: 163
Quote:
Originally Posted by seefor View Post
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.
 
Old 03-04-2009, 10:22 AM   #8
seefor
Member
 
Registered: Mar 2006
Posts: 34

Original Poster
Rep: Reputation: 15
Ok, I looked into both here is what I found:

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:
Code:
nmap -sU -p 161 -n -oG hoststemp.txt 192.168.1.0/24
Do you have a reference to using it with OIDs?

Again thanks for all the help

Last edited by seefor; 03-04-2009 at 12:15 PM.
 
  


Reply


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
Making shell script to 'locate' m4a files and delete them bd1308 Linux - Software 3 02-12-2006 11:44 AM
Making a shell script to enable/disable apache/mysql Lazy Foo' Programming 2 01-27-2006 10:07 AM
Odd problem with making a variable the output of a command in a shell script linux=future Programming 3 12-13-2005 10:45 PM
Making shell script a part of linux image mayureshchitale Linux - Newbie 1 07-06-2004 02:00 AM


All times are GMT -5. The time now is 08:19 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