Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!apple!ames!lll-winken!uunet!prcrs!paul From: paul@prcrs.UUCP (Paul Hite) Newsgroups: comp.unix.wizards Subject: Re: run level Summary: use who -r Keywords: init, run level, sysadm Message-ID: <1452@prcrs.UUCP> Date: 30 May 89 15:00:31 GMT References: <469@anvil.oz> Organization: PRC Realty Systems, McLean, VA Lines: 38 In article <469@anvil.oz>, michi@anvil.oz (Michael Henning) writes: > Is there some elegant and reliable > way (i.e. portable) of asking init at what run level it is ? > With System V, the who command has several options added to it. One option reports the current run state. I'm not sure that I would call this "elegant", but it does seem to be the intended System V way to obtain the current run state. Here is a fragment of a shell script that uses this: #! /bin/sh set `who -r` if [ "$7" = "S" ] ; then echo We are in single user mode echo I will remount all disk drives umount -a mount -t hfs -a fi One warning about this. At least on a HP-UX system, I have seen this fail. If you get to single user mode via shutdown or init S, then the run state as reported by who -r is correct. But if you interrupt to boot-up sequence and go directly to single user mode, it will be wrong. Since some versions of TFM get this wrong, here is the output from a who -r: . system boot May 5 02:49 2 0 S ^ ^ ^ | | | previous run state | | | | number of times current run | | state has been entered | | current run state I hope that this helps. Paul Hite PRC Realty Systems McLean,Va uunet!prcrs!paul (703) 556-2243 DOS is a four letter word!