Operating System - HP-UX
1832513 Members
4827 Online
110043 Solutions
New Discussion

how to get the hostname when in single user mode

 
SOLVED
Go to solution
curt larson_1
Honored Contributor

how to get the hostname when in single user mode

is there a way to get the host when boot into single user mode, i.e. startup scripts haven't run so no networking available, and the /usr, etc. filesystems aren't mounted?
10 REPLIES 10
Patrick Wallek
Honored Contributor
Solution

Re: how to get the hostname when in single user mode

# grep "HOSTNAME=" /etc/rc.config.d/netconf

Remember that normally /etc is NOT a separate filesystem. It is under the / filesystem.
Jeff Schussele
Honored Contributor

Re: how to get the hostname when in single user mode

Hi,

And if you mount /usr, you could run the hostname commnad.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
A. Clay Stephenson
Acclaimed Contributor

Re: how to get the hostname when in single user mode

I haven't knocked down to single user to test this but it should work:

echo "hostname/S" | adb /stand/vmunix /dev/kmem
If it ain't broke, I can fix that.
curt larson_1
Honored Contributor

Re: how to get the hostname when in single user mode

I had thought of using a file to save the name, but you have to keep that uptodate and there are other files that have the information, such as /etc/hosts.

And, Mr. Wallek has what I'm looking for a file where the there is only one entry and should be authoriative. althought grep is in /usr and unavailable, /sbin/awk should work just as well.

otherways, were writing a C program not using shared libraries. and the output from /sbin/uname -n, which is unknown in single user mode
A. Clay Stephenson
Acclaimed Contributor

Re: how to get the hostname when in single user mode

Forget mine, /usr has to be mounted for adb; it requires shared libraries.
If it ain't broke, I can fix that.
Sridhar Bhaskarla
Honored Contributor

Re: how to get the hostname when in single user mode

Just to add my 2 cents. "hostname" is set only during the rc scripts after the single user mode. So, even mounting /usr and other tricks may not help.

Patrick had the answer. That's the most possible hostname that would get assigned to the system later.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
A. Clay Stephenson
Acclaimed Contributor

Re: how to get the hostname when in single user mode

Okay, I have another method. We will ask the box ourselves with a statically linked program that you can install in /sbin.

-----------------------------------------
#include
#include

extern int errno;

int main()
{
int cc = 0;
char s[80];

cc = gethostname(s,(size_t) (sizeof(s) - 1));
if (cc == 0)
{
(void) printf("%s\n",s);
}
else
{
cc = (errno != 0) ? errno : -1;
(void) fprintf(stderr,"Gethostname failed. (%d)\n",cc);
}
return(cc);
}
--------------------------------------------

Compile gethostname.c like this (It will even compile with the Bundled compiler):

cc +DAportable -Wl,-a,archive -o gethostname gethostname.c

If it ain't broke, I can fix that.
Sijesh
Advisor

Re: how to get the hostname when in single user mode

#cat /etc/rc.config.d/netconf and look for HOSTNAME=

else mount /usr (vgchange -a y /dev/vg00 ;mount /dev/vg00/lvol7 /usr)
then
#grep "HOSTNAME=" /etc/rc.config.d/netconf





curt larson_1
Honored Contributor

Re: how to get the hostname when in single user mode

you can do this:
/sbin/awk '/HOSTNAME=/ {print;}' /etc/rc.config.d/netconf

but it returns lines and not really the value. And, with the possibilities of multiple lines, comments, and quoting, I think this works best for getting the value from netconf:

/sbin/sh -c ". /etc/rc.config.d/netconf;print $HOSTNAME"

Mr. Stephenson's program works. but it returns the same value as /sbin/uname -n would, i.e. it will report the hostname as "unknown" when in single user mode.
Bill Hassell
Honored Contributor

Re: how to get the hostname when in single user mode

AS you've discovered, the hostname is meaningless (unknown) in songle user mode. That because hostname is of no value without networking. The hostname is assigned during startup from the /sbin/init.d/hostname file. In detail, it is set in run level 1 definitions (/sbin/rc1.d) just after mounts and some kernel init has been completed. So all systems have the same hostname in single user mode.


Bill Hassell, sysadmin