HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: /etc/hosts script required: quick one!
Operating System - HP-UX
1826451
Members
4316
Online
109692
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
06-14-2002 03:30 AM
06-14-2002 03:30 AM
Hi all, back into my lab script creation time..
I'm looking for a script (don't ask why ;)) that:
1> checks for an undefined lan interface (can assume lan1 is free, but best to check)
ie: ifconfig lan1
if ERR
then
ifconfig lan1 192.168.1.1
else
ifconfig lan2
if ERR
then
ifconfig lan2 192.168.1.1
etc..
end
2> after assigning this lan,
need to look at lan0 (that hostname is tied to - can assume 0..)
lets say it's 10.1.2.3
then grep the hostname /lan0 ip in /etc/hosts.
3> /etc/hosts will then need to be modified to end up
with
192.168.1.1 hostname hostalias
127.0.0.1 loopback localhost
10.1.2.3 hostname hostalias
rather than the previous
127.0.0.1 loopback localhost
10.1.2.3 hostname hostalias
+ all the rest of the stuff in /etc/hosts remaining.
Thanks!
Bill
I'm looking for a script (don't ask why ;)) that:
1> checks for an undefined lan interface (can assume lan1 is free, but best to check)
ie: ifconfig lan1
if ERR
then
ifconfig lan1 192.168.1.1
else
ifconfig lan2
if ERR
then
ifconfig lan2 192.168.1.1
etc..
end
2> after assigning this lan,
need to look at lan0 (that hostname is tied to - can assume 0..)
lets say it's 10.1.2.3
then grep the hostname /lan0 ip in /etc/hosts.
3> /etc/hosts will then need to be modified to end up
with
192.168.1.1 hostname hostalias
127.0.0.1 loopback localhost
10.1.2.3 hostname hostalias
rather than the previous
127.0.0.1 loopback localhost
10.1.2.3 hostname hostalias
+ all the rest of the stuff in /etc/hosts remaining.
Thanks!
Bill
It works for me (tm)
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2002 04:02 AM
06-14-2002 04:02 AM
Solution
Bill
I use the following to give the status of a lan, it can be modified to notify of an un-configured interface, one found then run through the config of this found interface, either pulling the info from the script, command line or config file.
Etc/hosts will have to have an annotation in it to distinguish Lan0 so that its info can be pulled.
Just a few ideas.
---------------------------------------------
#! /usr/bin/sh
/usr/bin/uname -a
/usr/sbin/lanscan
ppas="0 1"
for ppa in $ppas
do
stat=`/usr/sbin/lanadmin 2>/dev/null < l
ppa $ppa
d
q
EOF
`
echo $ppa --- $stat
done
----------------------------------------------
Paula
I use the following to give the status of a lan, it can be modified to notify of an un-configured interface, one found then run through the config of this found interface, either pulling the info from the script, command line or config file.
Etc/hosts will have to have an annotation in it to distinguish Lan0 so that its info can be pulled.
Just a few ideas.
---------------------------------------------
#! /usr/bin/sh
/usr/bin/uname -a
/usr/sbin/lanscan
ppas="0 1"
for ppa in $ppas
do
stat=`/usr/sbin/lanadmin 2>/dev/null <
ppa $ppa
d
q
EOF
`
echo $ppa --- $stat
done
----------------------------------------------
Paula
If you can spell SysAdmin then you is one - anon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2002 04:15 AM
06-14-2002 04:15 AM
Re: /etc/hosts script required: quick one!
managed to throw something together..
But would prefer a more elegant ip comparisson before changing!
Still up for points!
#!/usr/bin/ksh
#
# add the hostname to the /etc/hosts first
THEIP=192.168.1.99
THEIP2=10.1.2.3
for lan in $(lanscan | grep lan | awk {'print $5'})
do
ifconfig $lan 1>/dev/null 2>/dev/null
if [[ $? = 0 ]]; then
echo "> $lan used \c: "
#
# making sure IP not used already
#
ifconfig $lan | grep inet | awk {'print $2'} | grep $THEIP
if [[ $? = 0 ]]; then
echo "> $THEIP already in use here"
echo "> IP to set now $THEIP2"
THEIP=$THEIP2
fi
else
echo "> using $lan"
ifconfig $lan $THEIP
break
fi
done
set -x
grep \# /etc/hosts > /tmp/hosts
echo "$THEIP\t$(hostname)\t$(hostname)." >> /tmp/hosts
grep -v \# /etc/hosts >> /tmp/hosts
But would prefer a more elegant ip comparisson before changing!
Still up for points!
#!/usr/bin/ksh
#
# add the hostname to the /etc/hosts first
THEIP=192.168.1.99
THEIP2=10.1.2.3
for lan in $(lanscan | grep lan | awk {'print $5'})
do
ifconfig $lan 1>/dev/null 2>/dev/null
if [[ $? = 0 ]]; then
echo "> $lan used \c: "
#
# making sure IP not used already
#
ifconfig $lan | grep inet | awk {'print $2'} | grep $THEIP
if [[ $? = 0 ]]; then
echo "> $THEIP already in use here"
echo "> IP to set now $THEIP2"
THEIP=$THEIP2
fi
else
echo "> using $lan"
ifconfig $lan $THEIP
break
fi
done
set -x
grep \# /etc/hosts > /tmp/hosts
echo "$THEIP\t$(hostname)\t$(hostname)." >> /tmp/hosts
grep -v \# /etc/hosts >> /tmp/hosts
It works for me (tm)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2002 07:42 AM
06-14-2002 07:42 AM
Re: /etc/hosts script required: quick one!
Hi Bill,
I do not know if you can rule out my thoughts because of your environment, but:
1) a dot in a grep expression stands for a single character wildcard ! See this :
# echo 1.1.1.1 > greptarget
# echo 121.121.2.2 >> greptarget
# grep 1.1.1.1 greptarget
1.1.1.1
121.121.2.2
# grep 1\.1\.1\.1 greptarget
1.1.1.1
121.121.2.2
# grep -e '1\.1\.1\.1' greptarget
1.1.1.1
So your THEIP variable will probably resolve to more than one possible target in /etc/hosts (probably not) ?
To be correct a logical expression ( -e ) with backslashed dots will be safe.
2) I have a system here with an unconfigured token-ring card, that does not show up in lanscan, although it is visible in ioscan. ifconfig lan1 says the interface does not exist, although it is physically in the box,
and had been configuered years ago. This might be token-ring specific, but consider that diffrent physical lanX can behave diffrent from ethernet (FDDI ? other ...).
3) If a box is configuered without LAN upon installation, and the network is configured later. The initial binding of the hostname is against the loopback interface (lo0:) which also does not appear in lanscan. Do not know if this makes any diffrence in your case.
4) Your modification of /tmp/hosts will sort all comments to the top if I analyzed correctly. For me this would not be good, because I have several comment headers for diffrent networks like this
# net one
a.b.c.1
a.b.c.2
# net two
c.d.e.4
c.d.e.5
Have a nice weekend
volker
I do not know if you can rule out my thoughts because of your environment, but:
1) a dot in a grep expression stands for a single character wildcard ! See this :
# echo 1.1.1.1 > greptarget
# echo 121.121.2.2 >> greptarget
# grep 1.1.1.1 greptarget
1.1.1.1
121.121.2.2
# grep 1\.1\.1\.1 greptarget
1.1.1.1
121.121.2.2
# grep -e '1\.1\.1\.1' greptarget
1.1.1.1
So your THEIP variable will probably resolve to more than one possible target in /etc/hosts (probably not) ?
To be correct a logical expression ( -e ) with backslashed dots will be safe.
2) I have a system here with an unconfigured token-ring card, that does not show up in lanscan, although it is visible in ioscan. ifconfig lan1 says the interface does not exist, although it is physically in the box,
and had been configuered years ago. This might be token-ring specific, but consider that diffrent physical lanX can behave diffrent from ethernet (FDDI ? other ...).
3) If a box is configuered without LAN upon installation, and the network is configured later. The initial binding of the hostname is against the loopback interface (lo0:) which also does not appear in lanscan. Do not know if this makes any diffrence in your case.
4) Your modification of /tmp/hosts will sort all comments to the top if I analyzed correctly. For me this would not be good, because I have several comment headers for diffrent networks like this
# net one
a.b.c.1
a.b.c.2
# net two
c.d.e.4
c.d.e.5
Have a nice weekend
volker
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP