- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- detect the run level from a shell script?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 06:00 AM
06-13-2002 06:00 AM
Note: In single user, /usr/bin is unavailable, etc. so the solution needs to work only with what is mounted in single-user.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 06:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 06:02 AM
06-13-2002 06:02 AM
Re: detect the run level from a shell script?
The who -r command give you this information. Read the man page for who command.
Regards,
Justo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 06:03 AM
06-13-2002 06:03 AM
Re: detect the run level from a shell script?
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.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 06:06 AM
06-13-2002 06:06 AM
Re: detect the run level from a shell script?
if [ ${RS} -eq 3 ]
then
echo "I'm in run-level 3"
else
echo "I ain't"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 06:09 AM
06-13-2002 06:09 AM
Re: detect the run level from a shell script?
You can't even cp it to sbin in it's current state:
mawenzi - /usr/sbin # chatr /usr/bin/who
/usr/bin/who:
shared executable
shared library dynamic path search:
SHLIB_PATH disabled second
embedded path disabled first Not Defined
shared library list:
dynamic /usr/lib/libc.2
shared library binding:
deferred
global hash table disabled
plabel caching disabled
shared vtable support disabled
static branch prediction disabled
executable from stack: D (default)
kernel assisted branch prediction enabled
lazy swap allocation disabled
text segment locking disabled
data segment locking disabled
third quadrant private data space disabled
fourth quadrant private data space disabled
data page size: D (default)
instruction page size: D (default)
mawenzi - /usr/sbin # chatr /sbin/vgchange
/sbin/vgchange:
shared executable
static branch prediction disabled
executable from stack: D (default)
kernel assisted branch prediction enabled
lazy swap allocation disabled
text segment locking disabled
data segment locking disabled
third quadrant private data space disabled
fourth quadrant private data space disabled
data page size: D (default)
instruction page size: D (default)
I'm sure chatr chan be used to make a static version, I don't know how though..
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 06:11 AM
06-13-2002 06:11 AM
Re: detect the run level from a shell script?
who -r command gives u the run level.
Piyush
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 06:15 AM
06-13-2002 06:15 AM
Re: detect the run level from a shell script?
if [ "`/sbin/who -r |
/sbin/awk '{print $3}'`" != "1" ]
then
# this is not single user
# my lines can go here
fi
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 06:21 AM
06-13-2002 06:21 AM
Re: detect the run level from a shell script?
Definition by run-level:
0 - halted
S - single user mode
1 - minimal system configuration
2 - multi-user mode
3 - exported file systems
4 - graphical interface managers
Have a look here for more information:
http://docs.hp.com/hpux/onlinedocs/os/startup.pdf
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 06:25 AM
06-13-2002 06:25 AM
Re: detect the run level from a shell script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 06:27 AM
06-13-2002 06:27 AM
Re: detect the run level from a shell script?
S=Single user state. All kill and start scripts in /sbin/rc0.d are executed.
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.
2=Multi-user state. Users are allowed to access the system. All kill and start scripts in /sbin/rc2.d are executed.
3=Networked multi-user state. NFS file systems can be exported. All kill and start scripts in /sbin/rc3.d are executed.
4=HP-VUE activated here. All kill and start scripts in /sbin/rc4.d are executed.
5=Not defined.
6=Not defined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 06:29 AM
06-13-2002 06:29 AM
Re: detect the run level from a shell script?
$ uname -a
HP-UX tsws1 B.11.11 U 9000/785 2006482480 unlimited-user license
$ ll /sbin/who
/sbin/who not found
$ whence who
/usr/bin/who
yukon(297)root# uname -a
HP-UX yukon B.11.00 U 9000/800 650349313 unlimited-user license
yukon(298)root# ll /sbin/who
/sbin/who not found
yukon(299)root# whence who
/usr/bin/who
Ahhh!, I did find a 10.20 system where it's located in /sbin.
Fred, what release are you running and how forward compatible do you want to be?
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 06:37 AM
06-13-2002 06:37 AM
Re: detect the run level from a shell script?
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?
Anyway I've got plenty if info now to get me into trouble, thanks folks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 06:41 AM
06-13-2002 06:41 AM
Re: detect the run level from a shell script?
In any case, good luck,
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 06:52 AM
06-13-2002 06:52 AM
Re: detect the run level from a shell script?
if [ "`/sbin/who -r |
/sbin/awk '{print $3}'`" = "3" ]
then
# my lines can go here
fi
And yeah, I suspect playing with /etc/profile is risky anyway.
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.
If I could do those things without playing with a system file, I would.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 07:23 AM
06-13-2002 07:23 AM
Re: detect the run level from a shell script?
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.
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.
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:
USRMOUNTED=$(/sbin/mount -l | /sbin/awk '/^\/usr\ /')
if [ -z "$USRMOUNTED" ]
then
SINGLEUSERMODE=/sbin/true
else
SINGLEUSERMODE=/sbin/false
fi
Now you can do something like this in /etc/profile:
if $SINGLEUSERMODE
then
do_something
else
do_another_something
fi
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:
case $0 in
-* ) export LOGINSHELL=/sbin/true;;
* ) export LOGINSHELL=/sbin/false;;
esac
# Interactive test
if [ -o interactive ]
then
export INTERACTIVESHELL=/sbin/true
else
export INTERACTIVESHELL=/sbin/false
fi
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:
if $INTERACTIVE
then
eval $(/sbin/ttytype -s)
fi
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 08:09 AM
06-13-2002 08:09 AM
Re: detect the run level from a shell script?
Thanks very much.