<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: detect the run level from a shell script? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744040#M68463</link>
    <description>Am I losing it?  My systems don't have who in /sbin (this sounds like the beginning of an Abbott and Costello routine).&lt;BR /&gt;$ uname -a&lt;BR /&gt;HP-UX tsws1 B.11.11 U 9000/785 2006482480 unlimited-user license&lt;BR /&gt;$ ll /sbin/who&lt;BR /&gt;/sbin/who not found&lt;BR /&gt;$ whence who&lt;BR /&gt;/usr/bin/who&lt;BR /&gt;yukon(297)root# uname -a&lt;BR /&gt;HP-UX yukon B.11.00 U 9000/800 650349313 unlimited-user license&lt;BR /&gt;yukon(298)root# ll /sbin/who&lt;BR /&gt;/sbin/who not found&lt;BR /&gt;yukon(299)root# whence who&lt;BR /&gt;/usr/bin/who&lt;BR /&gt;&lt;BR /&gt;Ahhh!, I did find a 10.20 system where it's located in /sbin.&lt;BR /&gt;&lt;BR /&gt;Fred, what release are you running and how forward compatible do you want to be?&lt;BR /&gt;&lt;BR /&gt;Pete</description>
    <pubDate>Thu, 13 Jun 2002 13:29:32 GMT</pubDate>
    <dc:creator>Pete Randall</dc:creator>
    <dc:date>2002-06-13T13:29:32Z</dc:date>
    <item>
      <title>detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744029#M68452</link>
      <description>I've added a few lines to /etc/profile which do not apply to single-user mode.  Is there a way that the script can detect the run level so I can skip those lines, if the thing is in single-user mode?&lt;BR /&gt;&lt;BR /&gt;Note: In single user, /usr/bin is unavailable, etc. so the solution needs to work only with what is mounted in single-user.&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jun 2002 13:00:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744029#M68452</guid>
      <dc:creator>Fred Martin_1</dc:creator>
      <dc:date>2002-06-13T13:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744030#M68453</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Execute:&lt;BR /&gt;&lt;BR /&gt;who -r | awk '{print $3}'&lt;BR /&gt;&lt;BR /&gt;Bye,&lt;BR /&gt;Rik</description>
      <pubDate>Thu, 13 Jun 2002 13:02:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744030#M68453</guid>
      <dc:creator>RikTytgat</dc:creator>
      <dc:date>2002-06-13T13:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744031#M68454</link>
      <description>Hi Fred,&lt;BR /&gt;&lt;BR /&gt;The who -r command give you this information. Read the man page for who command.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Justo.</description>
      <pubDate>Thu, 13 Jun 2002 13:02:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744031#M68454</guid>
      <dc:creator>Justo Exposito</dc:creator>
      <dc:date>2002-06-13T13:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744032#M68455</link>
      <description>Fred,&lt;BR /&gt;&lt;BR /&gt;You could add a rc2 script to the startup that touched a file, the presence of which would tell /etc/profile that you were not in single user mode.&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Thu, 13 Jun 2002 13:03:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744032#M68455</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2002-06-13T13:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744033#M68456</link>
      <description>RS=$(who -r | awk '{print $3}')&lt;BR /&gt;if [ ${RS} -eq 3 ]&lt;BR /&gt;then&lt;BR /&gt;  echo "I'm in run-level 3"&lt;BR /&gt;else&lt;BR /&gt;  echo "I ain't"&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jun 2002 13:06:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744033#M68456</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-06-13T13:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744034#M68457</link>
      <description>well, in single user, not sure if who works:&lt;BR /&gt;You can't even cp it to sbin in it's current state:&lt;BR /&gt;&lt;BR /&gt;mawenzi - /usr/sbin # chatr /usr/bin/who&lt;BR /&gt;/usr/bin/who:&lt;BR /&gt;         shared executable&lt;BR /&gt;         shared library dynamic path search:&lt;BR /&gt;             SHLIB_PATH     disabled  second&lt;BR /&gt;             embedded path  disabled  first  Not Defined&lt;BR /&gt;         shared library list:&lt;BR /&gt;             dynamic   /usr/lib/libc.2&lt;BR /&gt;         shared library binding:&lt;BR /&gt;             deferred&lt;BR /&gt;         global hash table disabled&lt;BR /&gt;         plabel caching disabled&lt;BR /&gt;         shared vtable support disabled&lt;BR /&gt;         static branch prediction disabled&lt;BR /&gt;         executable from stack: D (default)&lt;BR /&gt;         kernel assisted branch prediction enabled&lt;BR /&gt;         lazy swap allocation disabled&lt;BR /&gt;         text segment locking disabled&lt;BR /&gt;         data segment locking disabled&lt;BR /&gt;         third quadrant private data space disabled&lt;BR /&gt;         fourth quadrant private data space disabled&lt;BR /&gt;         data page size: D (default)&lt;BR /&gt;         instruction page size: D (default)&lt;BR /&gt;mawenzi - /usr/sbin # chatr /sbin/vgchange&lt;BR /&gt;/sbin/vgchange:&lt;BR /&gt;         shared executable&lt;BR /&gt;         static branch prediction disabled&lt;BR /&gt;         executable from stack: D (default)&lt;BR /&gt;         kernel assisted branch prediction enabled&lt;BR /&gt;         lazy swap allocation disabled&lt;BR /&gt;         text segment locking disabled&lt;BR /&gt;         data segment locking disabled&lt;BR /&gt;         third quadrant private data space disabled&lt;BR /&gt;         fourth quadrant private data space disabled&lt;BR /&gt;         data page size: D (default)&lt;BR /&gt;         instruction page size: D (default)&lt;BR /&gt;&lt;BR /&gt;I'm sure chatr chan be used to make a static version, I don't know how though..&lt;BR /&gt;&lt;BR /&gt;Later,&lt;BR /&gt;Bill</description>
      <pubDate>Thu, 13 Jun 2002 13:09:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744034#M68457</guid>
      <dc:creator>Bill McNAMARA_1</dc:creator>
      <dc:date>2002-06-13T13:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744035#M68458</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;who -r command gives u the run level.&lt;BR /&gt;&lt;BR /&gt;Piyush</description>
      <pubDate>Thu, 13 Jun 2002 13:11:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744035#M68458</guid>
      <dc:creator>PIYUSH D. PATEL</dc:creator>
      <dc:date>2002-06-13T13:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744036#M68459</link>
      <description>All good, thanks!  Assuming run level 1 is single user, this should work:&lt;BR /&gt;&lt;BR /&gt;if [ "`/sbin/who -r |&lt;BR /&gt;     /sbin/awk '{print $3}'`" != "1" ]&lt;BR /&gt;then&lt;BR /&gt;   # this is not single user&lt;BR /&gt;   # my lines can go here&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;By the way, I can't seem to find a list of run level values or defaults anywhere; have checked man on init, inittab, rc.&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jun 2002 13:15:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744036#M68459</guid>
      <dc:creator>Fred Martin_1</dc:creator>
      <dc:date>2002-06-13T13:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744037#M68460</link>
      <description>Hi Fred:&lt;BR /&gt;&lt;BR /&gt;Definition by run-level:&lt;BR /&gt;&lt;BR /&gt;0 - halted&lt;BR /&gt;S - single user mode&lt;BR /&gt;1 - minimal system configuration&lt;BR /&gt;2 - multi-user mode&lt;BR /&gt;3 - exported file systems&lt;BR /&gt;4 - graphical interface managers&lt;BR /&gt;&lt;BR /&gt;Have a look here for more information:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://docs.hp.com/hpux/onlinedocs/os/startup.pdf" target="_blank"&gt;http://docs.hp.com/hpux/onlinedocs/os/startup.pdf&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jun 2002 13:21:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744037#M68460</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-06-13T13:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744038#M68461</link>
      <description>Well int init man pages are about as close as you are going to get for run level values; the default run level is set in the 'initdefault' entry in /etc/inittab.&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jun 2002 13:25:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744038#M68461</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-06-13T13:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744039#M68462</link>
      <description>0=Halted/reboot level, All kill and start scripts in /sbin/rc0.d are executed.&lt;BR /&gt;S=Single user state. All kill and start scripts in /sbin/rc0.d are executed.&lt;BR /&gt;1=Boot time system configuration. Necessary system configuration is done at this state.(Example: hostname defined, FS mounted). All kill and start scripts on /sbin/rc1.d are executed.&lt;BR /&gt;2=Multi-user state. Users are allowed to access the system. All kill and start scripts in /sbin/rc2.d are executed.&lt;BR /&gt;3=Networked multi-user state. NFS file systems can be exported. All kill and start scripts in /sbin/rc3.d are executed.&lt;BR /&gt;4=HP-VUE activated here. All kill and start scripts in /sbin/rc4.d are executed.&lt;BR /&gt;5=Not defined.&lt;BR /&gt;6=Not defined&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jun 2002 13:27:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744039#M68462</guid>
      <dc:creator>S.K. Chan</dc:creator>
      <dc:date>2002-06-13T13:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744040#M68463</link>
      <description>Am I losing it?  My systems don't have who in /sbin (this sounds like the beginning of an Abbott and Costello routine).&lt;BR /&gt;$ uname -a&lt;BR /&gt;HP-UX tsws1 B.11.11 U 9000/785 2006482480 unlimited-user license&lt;BR /&gt;$ ll /sbin/who&lt;BR /&gt;/sbin/who not found&lt;BR /&gt;$ whence who&lt;BR /&gt;/usr/bin/who&lt;BR /&gt;yukon(297)root# uname -a&lt;BR /&gt;HP-UX yukon B.11.00 U 9000/800 650349313 unlimited-user license&lt;BR /&gt;yukon(298)root# ll /sbin/who&lt;BR /&gt;/sbin/who not found&lt;BR /&gt;yukon(299)root# whence who&lt;BR /&gt;/usr/bin/who&lt;BR /&gt;&lt;BR /&gt;Ahhh!, I did find a 10.20 system where it's located in /sbin.&lt;BR /&gt;&lt;BR /&gt;Fred, what release are you running and how forward compatible do you want to be?&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Thu, 13 Jun 2002 13:29:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744040#M68463</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2002-06-13T13:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744041#M68464</link>
      <description>Pete,&lt;BR /&gt;&lt;BR /&gt;I'm on 11.0 but upgraded from 10.20 - I do have /sbin/who, and it may have been left there from 10.20?&lt;BR /&gt;&lt;BR /&gt;Anyway I've got plenty if info now to get me into trouble, thanks folks.&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jun 2002 13:37:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744041#M68464</guid>
      <dc:creator>Fred Martin_1</dc:creator>
      <dc:date>2002-06-13T13:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744042#M68465</link>
      <description>I guess it must be a leftover from 10.20.  I'd just be leary of using a solution that's probably going to end up not working when you go to the next release - like 11i.&lt;BR /&gt;&lt;BR /&gt;In any case, good luck,&lt;BR /&gt;Pete</description>
      <pubDate>Thu, 13 Jun 2002 13:41:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744042#M68465</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2002-06-13T13:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744043#M68466</link>
      <description>I'd probably use this rather than what I wrote above, it's the compliment:&lt;BR /&gt;&lt;BR /&gt;if [ "`/sbin/who -r | &lt;BR /&gt;   /sbin/awk '{print $3}'`" = "3" ]&lt;BR /&gt;then &lt;BR /&gt;# my lines can go here &lt;BR /&gt;fi &lt;BR /&gt;&lt;BR /&gt;And yeah, I suspect playing with /etc/profile is risky anyway.&lt;BR /&gt;&lt;BR /&gt;The deal is, I need to check users that are logging in, to see if they are -not- coming in from my network (i.e. the internet) and want to 1) deliver a special message to them 2) check against an /etc/group to see if they are in the group of users that are allowed in.&lt;BR /&gt;&lt;BR /&gt;If I could do those things without playing with a system file, I would.&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jun 2002 13:52:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744043#M68466</guid>
      <dc:creator>Fred Martin_1</dc:creator>
      <dc:date>2002-06-13T13:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744044#M68467</link>
      <description>Here's the real story on single user mode detection:&lt;BR /&gt;&lt;BR /&gt;First, init (despite the man page descriptions) cannot take you to true singleuser mode. init is not the parent of every process and thus, init s (or S) will not remove all the unnecessary kernel process (including networking). init 1 is not single user mode either. The only reliable way to get to singleuser mode is an interrupted bootup.&lt;BR /&gt;&lt;BR /&gt;At 10.20, /sbin/who is there, but at 11.0 and higher, it was replaced with the program /sbin/getrunlvl. Unfortunately, neither program reliably reports singleuser mode! At 10.20, who often reports the last run level (ie, 3) even when in singleuser mode. This may be related to using shutdown 0 to get to single user mode rather than an interrupted reboot.  getrunlvl also has reliablility problems for single user mode.&lt;BR /&gt;&lt;BR /&gt;I had the same requirement for /etc/profile: detect singleuser mode and set a flag so that commands that are in /usr will be bypassed in the code. I finally concluded that the only way to detect this state is to determine if /usr is mounted. If it is, then we're not in true single user mode where only / and possibly /stand are mounted. Here is a code snippet from my /etc/profile:&lt;BR /&gt;&lt;BR /&gt;  USRMOUNTED=$(/sbin/mount -l | /sbin/awk '/^\/usr\ /')&lt;BR /&gt;  if [ -z "$USRMOUNTED" ]&lt;BR /&gt;  then&lt;BR /&gt;     SINGLEUSERMODE=/sbin/true&lt;BR /&gt;  else&lt;BR /&gt;     SINGLEUSERMODE=/sbin/false&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;Now you can do something like this in /etc/profile:&lt;BR /&gt;&lt;BR /&gt;if $SINGLEUSERMODE&lt;BR /&gt;then&lt;BR /&gt;do_something&lt;BR /&gt;else&lt;BR /&gt;do_another_something&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;A similar construct in /etc/profile is to determine if /etc/profile is being run in a batch job (ie, part of an su - user_name script).  Here's the code snippet:&lt;BR /&gt;&lt;BR /&gt;  case $0 in&lt;BR /&gt;     -* ) export LOGINSHELL=/sbin/true;;&lt;BR /&gt;      * ) export LOGINSHELL=/sbin/false;;&lt;BR /&gt;  esac&lt;BR /&gt;&lt;BR /&gt;# Interactive test&lt;BR /&gt;&lt;BR /&gt;  if [ -o interactive ]&lt;BR /&gt;  then&lt;BR /&gt;     export INTERACTIVESHELL=/sbin/true&lt;BR /&gt;  else&lt;BR /&gt;     export INTERACTIVESHELL=/sbin/false&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;So the variable $LOGINSHELL indicates that this script is being run at the lowest level (because there's a - in front of the shell's name), and the variable $INTERACTIVE menas that there is someone at a keyboard (as opposed to a cron job or batch script). This way, you can eliminate "not a typewriter" messages as in:&lt;BR /&gt;&lt;BR /&gt;if $INTERACTIVE&lt;BR /&gt;then&lt;BR /&gt;eval $(/sbin/ttytype -s)&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jun 2002 14:23:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744044#M68467</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2002-06-13T14:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: detect the run level from a shell script?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744045#M68468</link>
      <description>Wow too bad you can't get 20 points :)&lt;BR /&gt;&lt;BR /&gt;Thanks very much.&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jun 2002 15:09:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/detect-the-run-level-from-a-shell-script/m-p/2744045#M68468</guid>
      <dc:creator>Fred Martin_1</dc:creator>
      <dc:date>2002-06-13T15:09:54Z</dc:date>
    </item>
  </channel>
</rss>

