| Author |
Message |
Brett *nix forums beginner
Joined: 14 Apr 2005
Posts: 9
|
Posted: Thu Jul 20, 2006 6:58 pm Post subject:
How do I determine if a virtual hostname is actually on my local host?
|
|
|
Hi!
I'm looking for a simple way to determine if a virtual hostname is
actually on the host a script I have is running on. For example, assume
(2) hosts, hostA & hostB and (1) virtual host vhostA.
Basically I am going to have the same script running on both hosts. But
in my script, I need to have a snipet that will let me know whether
vhost is tied to the machine I'm running on.
I'd imagine I can do something with looking at the output of "ifconfig
-a", and checking each interface, but I was looking for a simplier
solution that someone else might see.
Thanks,
Brett |
|
| Back to top |
|
 |
Bill Marcum *nix forums Guru
Joined: 28 Mar 2005
Posts: 1264
|
Posted: Thu Jul 20, 2006 7:11 pm Post subject:
Re: How do I determine if a virtual hostname is actually on my local host?
|
|
|
On 20 Jul 2006 11:58:23 -0700, Brett
<bbartick@us.nomura.com> wrote:
| Quote: | Hi!
I'm looking for a simple way to determine if a virtual hostname is
actually on the host a script I have is running on. For example, assume
(2) hosts, hostA & hostB and (1) virtual host vhostA.
Basically I am going to have the same script running on both hosts. But
in my script, I need to have a snipet that will let me know whether
vhost is tied to the machine I'm running on.
I'd imagine I can do something with looking at the output of "ifconfig
-a", and checking each interface, but I was looking for a simplier
solution that someone else might see.
man host |
--
BOFH excuse #208:
Your mail is being routed through Germany ... and they're censoring us. |
|
| Back to top |
|
 |
#2pencil *nix forums addict
Joined: 09 Jun 2005
Posts: 55
|
Posted: Thu Jul 20, 2006 7:12 pm Post subject:
Re: How do I determine if a virtual hostname is actually on my local host?
|
|
|
| Quote: | Hi!
I'm looking for a simple way to determine if a virtual hostname is
actually on the host a script I have is running on. For example, assume
(2) hosts, hostA & hostB and (1) virtual host vhostA.
Basically I am going to have the same script running on both hosts. But
in my script, I need to have a snipet that will let me know whether
vhost is tied to the machine I'm running on.
I'd imagine I can do something with looking at the output of "ifconfig
-a", and checking each interface, but I was looking for a simplier
solution that someone else might see.
Thanks,
Brett
|
Are you talking about the hosts file?
cat /etc/hosts | grep host
Or virtual hosts through apache?
cat apache.conf | grep host
-#2pencil-
www.AkronCdnr.com |
|
| Back to top |
|
 |
Brett *nix forums beginner
Joined: 14 Apr 2005
Posts: 9
|
Posted: Thu Jul 20, 2006 7:24 pm Post subject:
Re: How do I determine if a virtual hostname is actually on my local host?
|
|
|
#2pencil wrote:
| Quote: | Are you talking about the hosts file?
cat /etc/hosts | grep host
Or virtual hosts through apache?
cat apache.conf | grep host
-#2pencil-
|
In this particular case I'm talking about a virtual hostname assigned
on a Solaris system.
Here's a better picture:
hostA has the following interfaces configured
ce0: hostA
ce0:1 vhost1
ce0:2 vhost3
ce0:3 vhost4
hostB has the following interfaces configured
ce0: hostB
ce0:1 vhost2
Let's say hostname vhost4 is "widgetserver". Now in this particular
environment vhost4 can float between hostA & hostB. How do I determine
in my script if I'm running on the "widgetserver"?
Thanks,
Brett |
|
| Back to top |
|
 |
Chris F.A. Johnson *nix forums Guru
Joined: 20 Feb 2005
Posts: 2268
|
Posted: Thu Jul 20, 2006 7:45 pm Post subject:
Re: How do I determine if a virtual hostname is actually on my local host?
|
|
|
On 2006-07-20, Brett wrote:
| Quote: | #2pencil wrote:
Are you talking about the hosts file?
cat /etc/hosts | grep host
Or virtual hosts through apache?
cat apache.conf | grep host
-#2pencil-
In this particular case I'm talking about a virtual hostname assigned
on a Solaris system.
|
How is it "assigned"?
| Quote: | Here's a better picture:
hostA has the following interfaces configured
ce0: hostA
ce0:1 vhost1
ce0:2 vhost3
ce0:3 vhost4
hostB has the following interfaces configured
ce0: hostB
ce0:1 vhost2
|
Where is the configuration stored? Wherever it is, grep that file.
| Quote: | Let's say hostname vhost4 is "widgetserver". Now in this particular
environment vhost4 can float between hostA & hostB. How do I determine
in my script if I'm running on the "widgetserver"?
|
By looking in the appropriate file with grep (but don't use cat).
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence |
|
| Back to top |
|
 |
Radoulov, Dimitre *nix forums beginner
Joined: 14 Dec 2005
Posts: 26
|
Posted: Thu Jul 20, 2006 8:31 pm Post subject:
Re: How do I determine if a virtual hostname is actually on my local host?
|
|
|
"Brett" <bbartick@us.nomura.com> wrote in message
news:1153421903.493736.296050@h48g2000cwc.googlegroups.com...
| Quote: | Hi!
I'm looking for a simple way to determine if a virtual hostname is
actually on the host a script I have is running on. For example, assume
(2) hosts, hostA & hostB and (1) virtual host vhostA.
Basically I am going to have the same script running on both hosts. But
in my script, I need to have a snipet that will let me know whether
vhost is tied to the machine I'm running on.
I'd imagine I can do something with looking at the output of "ifconfig
-a", and checking each interface, but I was looking for a simplier
solution that someone else might see.
|
Get the network interface from the hosts file and test it on both nodes:
ifconfig <net_interface> > /dev/null 2>&1 && echo "VH runing on
$(hostname)" || echo "VH is not running on $(hostname)"
For example:
xxx020$ ifconfig eri0:2 > /dev/null 2>&1 && echo "VH runing on $(hostname)"
|| "VH is not running on $(hostname)"
VH runing on xxx020
Regards
Dimitre |
|
| Back to top |
|
 |
Brett *nix forums beginner
Joined: 14 Apr 2005
Posts: 9
|
Posted: Thu Jul 20, 2006 9:05 pm Post subject:
Re: How do I determine if a virtual hostname is actually on my local host?
|
|
|
Radoulov, Dimitre wrote:
| Quote: |
Get the network interface from the hosts file and test it on both nodes:
ifconfig <net_interface> > /dev/null 2>&1 && echo "VH runing on
$(hostname)" || echo "VH is not running on $(hostname)"
For example:
xxx020$ ifconfig eri0:2 > /dev/null 2>&1 && echo "VH runing on $(hostname)"
|| "VH is not running on $(hostname)"
VH runing on xxx020
|
Thanks. I just wrote something quick along the same lines. I guess I
was looking for something even simplier and more eloquent.
This will return 1 if the virtual host is active on this physical node,
0 otherwise.
#!/bin/sh
if [ "$#" -ne "1" ]; then
echo "usage: `basename $0` hostname"
exit 0
fi
HOST="$1"
IP="`getent hosts $HOST | awk '{print $1}'"
list="`ifconfig -a | awk '/inet/ {print $2}'`"
for i in $list
do
[ "$i" = "$IP" ] && exit 1
done
exit 0 |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|