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
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
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
тАО04-16-2007 11:56 PM
тАО04-16-2007 11:56 PM
For loop
Can anyone help me with a case how to ping x.x.x.0 to x.x.x.255 and put the ones which are alive to a text file ??
Thanks in advance...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2007 12:13 AM
тАО04-17-2007 12:13 AM
Re: For loop
typeset -i index=0
while [ $index -le 255 ]; do
ping xxx.$index
if [ $? -eq 0 ]; then
echo xxx.$index >> alive.file
fi
(( index=index + 1 ))
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2007 12:34 AM
тАО04-17-2007 12:34 AM
Re: For loop
bash-3.00# ./ping.sh
./ping.sh: typeset: not found
./ping.sh: test: argument expected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2007 12:42 AM
тАО04-17-2007 12:42 AM
Re: For loop
A real shell recognizes typeset. I thought bash was ksh/sh like? Perhaps you should use the real shell in your scripts.
You can replace typeset by just:
index=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2007 12:42 AM
тАО04-17-2007 12:42 AM
Re: For loop
Bash uses 'declare' instead of 'typeset'.
You probably also want to amend your ping in Dennis' script to:
# ping xxx.$index -n 1
...such that only one ping is sent for each address.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2007 02:54 AM
тАО04-17-2007 02:54 AM
Re: For loop
$ echo $0
-bash
$ echo ${BASH_VERSINFO[*]}
3 00 15 1 release i386-redhat-linux-gnu
$ typeset -i some_int=42
$ declare -i|grep some
declare -i some_int="42"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2007 06:43 AM
тАО04-17-2007 06:43 AM
Re: For loop
Basic docu:
http://perldoc.perl.org/Net/Ping.html
Extended example usage in attachment to Clay's note in:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=22018
Simple example for your case:
--------------------- ping_network.pl -----
use strict;
use Net::Ping;
my $timeout = 2;
my $network = shift;
($network =~ !/\d+\.\d+\.\d+/) or die "Please provide nextwork adrress as xx.xx.xx";
my $p = Net::Ping->new('tcp');
foreach (0..255) {
my $host = "$network.$_";
my $stat = $p->ping($host,$timeout);
# printf "%s %d %s\n", $host, $stat, $stat? 'up' : 'down';
print "$host\n" if $stat;
}
$p->close();
------------------------------
# perl ping_network.pl 192.168.1 > up.txt
Hope this helps some,
Hein van den Heuvel (at gmail dot com)
HvdH Performance Consulting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2007 07:35 PM
тАО04-17-2007 07:35 PM
Re: For loop
One thing noteworthy about it is
that it can be employed more universal than an ordinary ping command.
For one (as Hein demonstrated), you can emit ordinary TCP packets and thus don't require root privileges or a setuid script unlike with ICMP packets.
Even better yet, it allows you to virtually ping every service by selection of the destination port.
Albeit, if you are an OO purist you probably would frown on the Net::Ping module's bad interface that it doesn't offer a proper accessor for setting the port but rather requires the user to mangle with the Net::Ping object like so:
use Net::Ping;
my $p = Net::Ping->new('tcp');
# setting to SSH's registered port
$p->{port_num} = getservbyname('ssh', 'tcp');