cancel
Showing results for
Did you mean:

how to increment a number

SOLVED
Go to solution
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
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???"
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???"
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.

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
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???"
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???"
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
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
Honored Contributor

Re: how to increment a number

"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???"
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
Valued Contributor
Solution

Re: how to increment a number

Generate the list pretty quick with this.
Just change the -le 150 to the last IP number i used 150 as example, and change xx.xx as well.

hou00us:~> i=0; while [ \$i -le 150 ]; do printf "10.xx.xx.%d\n" \$i ;i=`expr \$i + 1`; done

10.xx.xx.0
10.xx.xx.1
10.xx.xx.2
10.xx.xx.3
10.xx.xx.4
10.xx.xx.5
10.xx.xx.6
10.xx.xx.7
10.xx.xx.8
10.xx.xx.9
10.xx.xx.10
<<>>
10.xx.xx.150
Honored Contributor

Re: how to increment a number

c=0;
do
((c=c+\$a))
done
Honored Contributor

Re: how to increment a number

Charles,
If you use bash shell you can use a for loop
very similar to C language syntax

for ((i=1; i<=100; i++))
do
echo \$i
done
Honored Contributor

Re: how to increment a number

hi Charles,

below an example of the nmap output:
=========================================
# nmap -sP 1.2.3.0/24
Starting nmap 3.70 ( http://www.insecure.org/nmap/ ) at 2007-07-23 09:14 MUT
Host 1.2.3.0 seems to be a subnet broadcast address (returned 10 extra pings). Note -- the actual IP also responded.
Host 1.2.3.1 appears to be up.
Host 1.2.3.2 appears to be up.
Host 1.2.3.3 appears to be up.
Host 1.2.3.4 appears to be up.
Host 1.2.3.5 appears to be up.
Host 1.2.3.6 appears to be up.
Host 1.2.3.7 appears to be up.
Host 1.2.3.8 appears to be up.
Host 1.2.3.9 appears to be up.
...
Host 1.2.3.251 appears to be up.
Host 1.2.3.252 appears to be up.
Host 1.2.3.253 appears to be up.
Host 1.2.3.254 appears to be up.
Host 1.2.3.255 seems to be a subnet broadcast address (returned 13 extra pings). Note -- the actual IP also responded.
Nmap run completed -- 256 IP addresses (167 hosts up) scanned in 6.706 seconds

=========================================

See if this is acceptable else we will have to work it out using scripts!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Trusted Contributor

Re: how to increment a number

situation resolved, Thanks to all who answered the call.

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

Re: how to increment a number

Done.
"Not everything that can be counted counts, and not everything that counts can be counted" A. Einstein