[comp.unix.questions] Command to obtain current run level?

steve@acich.UUCP (Steve Westfall) (08/04/87)

Is there a shell command (or a system call) in System V UNIX that
will return the value of the current run state?  I would like to use
such a feature in some administrative shell scripts on our system.

-- 
Steve Westfall
Automated Concepts, Inc. - Chicago
(312) 346-8640
UUCP Mail:  ihnp4!acich!steve

jv@mhres.mh.nl (Johan Vromans) (08/05/87)

In article <241@acich.UUCP>, steve@acich.UUCP (Steve Westfall) writes:
> Is there a shell command (or a system call) in System V UNIX that
> will return the value of the current run state?  I would like to use
> such a feature in some administrative shell scripts on our system.

Try "who -r". It should return a line like

  " .       system boot  Jul 20 14:34    2    0    S"
                                         ^    ^    ^
                                        CRL   #    PRV

with CRL current run level, # the #st time this run level is
invoked, and PRV the previous run level.


-- 
Johan Vromans                           | jv@mh.nl via mcvax and seismo
Multihouse N.V., Gouda, the Netherlands | uucp: ..{seismo!}mcvax!mh.nl!jv
"It is better to light a candle than to curse the darkness"

heiby@mcdchg.UUCP (Ron Heiby) (08/06/87)

Check out the man page for the "who" command.  With the "-r" option on
my system, we get:
   .       run-level 2  Aug  5 13:56    2    0    S
It is a fairly simple matter to pick off the particular field of interest.
-- 
Ron Heiby, heiby@mcdchg.UUCP	Moderator: comp.newprod & comp.unix
"We are a gentle, loving people; And we are singing, singing for our still . 

allbery@ncoast.UUCP (Brandon Allbery) (08/08/87)

As quoted from <241@acich.UUCP> by steve@acich.UUCP (Steve Westfall):
+---------------
| Is there a shell command (or a system call) in System V UNIX that
| will return the value of the current run state?  I would like to use
| such a feature in some administrative shell scripts on our system.
+---------------

set -- `who -r`
echo $2

In case you're interested, "who -r" prints something like:

run-level 2   ... (stuff including time the machine entered the run level) ...
-- 
 Brandon S. Allbery, moderator of comp.sources.misc and comp.binaries.ibm.pc
  {{harvard,mit-eddie}!necntc,well!hoptoad,sun!cwruecmp!hal}!ncoast!allbery
ARPA: necntc!ncoast!allbery@harvard.harvard.edu  Fido: 157/502  MCI: BALLBERY
   <<ncoast Public Access UNIX: +1 216 781 6201 24hrs. 300/1200/2400 baud>>

kai@ihlpa.ATT.COM (Irwin) (08/12/87)

In article <241@acich.UUCP>, steve@acich.UUCP (Steve Westfall) writes:
> Is there a shell command (or a system call) in System V UNIX that
> will return the value of the current run state?  I would like to use
> such a feature in some administrative shell scripts on our system.
> 
> -- 
> Steve Westfall
> Automated Concepts, Inc. - Chicago
> (312) 346-8640
> UUCP Mail:  ihnp4!acich!steve

"who -r" will tell you the run state and the time it was achived

Ken A. Irwin
AT&T Bell Labs, Naperville
IHP 1A332
(312) 416-4485