- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Searching machines in a subnet
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
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
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-11-2002 03:01 AM
08-11-2002 03:01 AM
I would like to search the list of machines within the following subnets in a NIS domain:
180.30.201.xx
180.30.202.xx
180.30.203.xx
180.30.204.xx
(and the list continues until 180.30.211.xx)
I could do the following continuosly:
grep "180.30.201" /var/yp/src/hosts
But the method above would list all machines within the subnet 180.30.201.xx, 180.30.202, etc...
I would like to have only the first instance of a machine within those subnets obtained from the /var/yp/src/hosts file. For each instance of machines obtained, I would like it to be piped into a file.
Could someone show me how do I write a script to do that?
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2002 12:22 AM
08-12-2002 12:22 AM
SolutionAdd |head -n 1 >> /tmp/log to the grep to get 1 line
let x=201
while [ "$x" -le "211" ]
do
grep 18.130.$x /var/yp/src/hosts|head -n 1
let x=$x+1
done
Will work as a script
script > /tmp/lis
steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2002 05:25 AM
08-12-2002 05:25 AM
Re: Searching machines in a subnet
i.e., ping 180.30.201.255 - that would get you all the hosts on the 201 subnet that were up.
Then Head that - if you just want the first one, and >> it to a file, (or use spool)
Then nslookup on the ip address to arrive at the host name. Or ypcat -k ipaddress hosts - if they are all in the same nis domain.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2002 07:29 PM
08-13-2002 07:29 PM
Re: Searching machines in a subnet
Something like this should work.
grep -E '180\.30\.2(0[0-9]|1[01])' | sort -unt. -k 1i,3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2002 07:31 PM
08-13-2002 07:31 PM
Re: Searching machines in a subnet
Oops. I forgot to input the file.
grep -E '180\.30\.2(0[0-9]|1[01])' < /var/yp/src/hosts | sort -unt. -k 1i,3