niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » shell
How do I determine if a virtual hostname is actually on my local host?
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
Author Message
Brett
*nix forums beginner


Joined: 14 Apr 2005
Posts: 9

PostPosted: Thu Jul 20, 2006 6:58 pm    Post subject: How do I determine if a virtual hostname is actually on my local host? Reply with 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
Back to top
Bill Marcum
*nix forums Guru


Joined: 28 Mar 2005
Posts: 1264

PostPosted: Thu Jul 20, 2006 7:11 pm    Post subject: Re: How do I determine if a virtual hostname is actually on my local host? Reply with quote

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

PostPosted: Thu Jul 20, 2006 7:12 pm    Post subject: Re: How do I determine if a virtual hostname is actually on my local host? Reply with quote

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

PostPosted: Thu Jul 20, 2006 7:24 pm    Post subject: Re: How do I determine if a virtual hostname is actually on my local host? Reply with quote

#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

PostPosted: Thu Jul 20, 2006 7:45 pm    Post subject: Re: How do I determine if a virtual hostname is actually on my local host? Reply with quote

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

PostPosted: Thu Jul 20, 2006 8:31 pm    Post subject: Re: How do I determine if a virtual hostname is actually on my local host? Reply with quote

"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

PostPosted: Thu Jul 20, 2006 9:05 pm    Post subject: Re: How do I determine if a virtual hostname is actually on my local host? Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
The time now is Mon Dec 01, 2008 9:00 pm | All times are GMT
navigation Forum index » Programming » shell
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts spoofed local email addresses watkykjy Postfix 0 Thu Nov 20, 2008 8:49 am
No new posts Postfix 2.3.8 Virtual problem Blotto Postfix 0 Fri Apr 04, 2008 6:11 am
No new posts Postfix sending problem for local domain remote email monkey_magix Postfix 0 Mon Sep 10, 2007 10:17 am
No new posts determine pointer to point to array or single item during... yancheng.cheok@gmail.com C++ 5 Fri Jul 21, 2006 1:17 am
No new posts Relaying for not really trusted local servers Magnus Naeslund(k) Postfix 4 Thu Jul 20, 2006 6:02 pm

Cheap mp3 players | Credit Cards | Home Loan | Loans | Buy PSP
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2111s ][ Queries: 16 (0.1193s) ][ GZIP on - Debug on ]