Operating System - Linux
1827879 Members
1352 Online
109969 Solutions
New Discussion

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
Justin_99
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
skt_skt
Honored Contributor

Re: how to increment a number

c=0;
command|while read a
do
((c=c+$a))
done
Mike Stroyan
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
Yogeeraj_1
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.
MAC Address: 00:0E:38:6F:FB:00 (Cisco Systems)
Host 1.2.3.1 appears to be up.
MAC Address: 00:03:6B:A7:0A:60 (Cisco Systems)
Host 1.2.3.2 appears to be up.
MAC Address: 00:17:E0:7E:98:96 (Unknown)
Host 1.2.3.3 appears to be up.
MAC Address: 00:0F:F7:16:1F:1E (Cisco Systems)
Host 1.2.3.4 appears to be up.
MAC Address: 00:0F:F7:16:1F:22 (Cisco Systems)
Host 1.2.3.5 appears to be up.
MAC Address: 00:11:85:F9:49:7A (Unknown)
Host 1.2.3.6 appears to be up.
MAC Address: 00:0E:38:50:97:80 (Cisco Systems)
Host 1.2.3.7 appears to be up.
MAC Address: 00:12:79:CF:55:ED (Unknown)
Host 1.2.3.8 appears to be up.
MAC Address: 00:12:79:CF:56:9F (Unknown)
Host 1.2.3.9 appears to be up.
MAC Address: 00:12:79:CF:55:ED (Unknown)
...
Host 1.2.3.251 appears to be up.
MAC Address: 00:16:17:5D:07:31 (Unknown)
Host 1.2.3.252 appears to be up.
MAC Address: 00:16:17:5C:EA:5C (Unknown)
Host 1.2.3.253 appears to be up.
MAC Address: 00:0C:29:74:2E:79 (VMware)
Host 1.2.3.254 appears to be up.
MAC Address: 00:0E:38:6F:FB:00 (Cisco Systems)
Host 1.2.3.255 seems to be a subnet broadcast address (returned 13 extra pings). Note -- the actual IP also responded.
MAC Address: 00:0E:38:6F:FB:00 (Cisco Systems)
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)
Charles Holland
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
Charles Holland
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