- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- while loop help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 12:16 AM
тАО08-14-2007 12:16 AM
I am checking a range of IP addresses and would like to manipulate the second octet once the third octet has reached 254.
here is what I have so far:
#!/bin/ksh
IP1=0
IP2=10
while [ $IP1 -lt 255 ]
do
IP1=$((IP1+1))
for NET in 68 200 201 202
do
ping -w 1 -c 1 10.$IP2.$IP1.$NET
if [[ $? -ne 0 ]] ; then
echo "ERROR: IP 10.$IP2.$IP1.$NET cannot be connected" > netfile.error
else
echo "OK: IP 10.$IP2.$IP1.$NET can be connected" > netfile.ok
fi
done
done
once all 10.10.254.x have been ping'd i then need to check all ranges for
10.11.x.x
10.12.x.x
how can I use the syntax to add one more range to the second octet?
Thanks
Chris
Solved! Go to Solution.
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 01:16 AM
тАО08-14-2007 01:16 AM
Re: while loop help
-w is not an option for ping under HPUX.
Can you try without this option
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 01:19 AM
тАО08-14-2007 01:19 AM
SolutionSimply add another (outer) loop. For example:
#!/usr/bin/sh
typeset -i IP1=0
for IP2 in 10 11 12
do
IP1=0
while [ ${IP1} -lt 255 ]
do
IP1=$((IP1+1))
for NET in 68 200 201 202
do
ping -w 1 -c 1 10.${IP2}.${IP1}.${NET}
if [[ $? -ne 0 ]] ; then
echo "ERROR: IP 10.${IP2}.${IP1}.${NET} cannot be connected" \
> netfile.error
else
echo "OK: IP 10.${IP2}.${IP1}.${NET} can be connected" > netfile.ok
fi
done
done
done
...Notice, too, that I changed your variable declaration to a typeset integer for faster arithmetic and surrounded your variables with curly braces --- a good habit to learn to avoid ambiguity in parameter substitution.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 01:28 AM
тАО08-14-2007 01:28 AM
Re: while loop help
I have actually worked out a solution however could do with a more advanced script:
#!/bin/ksh
IP1=0
IP2=10
>netfile.error
>netfile.ok
while [[ $IP1 -lt 255 && $IP2 -lt 13 ]]
do
if [[ $IP1 -lt 254 ]] ; then
IP1=$IP1
else
IP1=0
IP2=$((IP2+1))
fi
IP1=$((IP1+1))
for NET in 68 200 201 202
do
ping -w 1 -c 1 10.$IP2.$IP1.$NET
if [[ $? -ne 0 ]] ; then
echo "ERROR: IP 10.$IP2.$IP1.$NET cannot be connected" >> netfile.error
else
echo "OK: IP 10.$IP2.$IP1.$NET can be connected" >> netfile.ok
fi
done
done
not use if this is working correctly as it is running through now.
What I would like is a solution that allows me to check all IP's on a range of networks and each octet being incremented:
check
10.1.1.2
10.1.1.3
etc
then check
10.1.2.1
10.1.2.2
10.1.2.3
etc
then check
10.2.1.1
10.2.1.2
10.2.1.3
etc
how can I easily increment each octet?
many thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 01:33 AM
тАО08-14-2007 01:33 AM
Re: while loop help
> What I would like is a solution that allows me to check all IP's on a range of networks and each octet being incremented:
Again, nested loops to increment each octet is all that you need. Simply be sure to re-initialize the low-order octets everytime you increment a higher-order one. I showed the addition of a 'for' loop only because it appeared that you wanted only a few ranges. Use multiple 'while' loops.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2007 05:03 AM
тАО08-14-2007 05:03 AM
Re: while loop help
- Tags:
- ping