how to increment a number

 
SOLVED
Go to solution
Charles Holland
Trusted Contributor

how to increment a number

This is my script: (not complete yet have to incorporate a do loop and an if count is > 100 to stop

count=0
echo $count
perform some function
(($count = $count + 1))
echo " the new count is "$count

Purpose is to check 100 things and the only thing different is the last diget(s)

It can't be that hard, but it has been a LONG day.

Points awarded promptly.
"Not everything that can be counted counts, and not everything that counts can be counted" A. Einstein
15 REPLIES 15
Court Campbell
Honored Contributor

Re: how to increment a number

This may give you a good start

for x in `seq 1 100`
do
echo $x
done
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Court Campbell
Honored Contributor

Re: how to increment a number

if you post more about what you are trying to accomplish with examples the community would be more than glad to help out.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Charles Holland
Trusted Contributor

Re: how to increment a number

Court,
Thanks for the reply. Basically we would like a script to go out on our network and see which IP's exist.

Start with 1.2.3.X

Do loop begins here
Ping to see if 1.2.3.X exists >> /tmp/ping_results
test to see if X is = 256
if it is exit
if not increment X + 1 (and remain in loop)
end

Charles
"Not everything that can be counted counts, and not everything that counts can be counted" A. Einstein
Court Campbell
Honored Contributor

Re: how to increment a number

I am all for scripting, but I think an easier solution would be to download angry ip scanner on a windows machine and scan the whole subnet.

http://www.angryziber.com/ipscan/
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Court Campbell
Honored Contributor

Re: how to increment a number

and you could always use nmap.

# nmap -sP 192.168.10.0/24
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Charles Holland
Trusted Contributor

Re: how to increment a number

With this script and an in_list file containing all the addresses to test it works fine

for I in `cat /root/in_list`
do
echo " Now testing address" $I
ping -c 2 $I >> /tmp/out_list
echo " "
done

I just don't want to create the entire in_list file.

I'll look at the link you provided and eval.

Charles
"Not everything that can be counted counts, and not everything that counts can be counted" A. Einstein
Charles Holland
Trusted Contributor

Re: how to increment a number

what is nmap? I have looked on my HPUX boxes, my Linux box and tried it from a command window on my desktop.

"Not everything that can be counted counts, and not everything that counts can be counted" A. Einstein
Court Campbell
Honored Contributor

Re: how to increment a number

You would need to download nmap.

http://insecure.org/nmap/download.html
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Charles Holland
Trusted Contributor

Re: how to increment a number

I have tried the first link you provided. I tried running in from the web site and our AV would not allow it to run. I downloaded the .ZIP file and tried to extract it but the AV rejected it again.

We will look at the nmap product and see what it looks like.
"Not everything that can be counted counts, and not everything that counts can be counted" A. Einstein