Runlevel testing in init scripts

DJ Lucas dj_me at
Mon Sep 9 23:29:31 PDT 2002


While I'm not sure anyone beyond myself is actually interested in this
working, as most people can live with the yellow [ATTN]s, it's kinda struck
me as unclean since I started with LFS and I wanted to do some checking in
the init scripts.  I've finally managed to make what I have thus far,
somewhat clean....clean enough for me, but suggestions and flames welcome
;-). This seemed a little OT for BLFS support, so I'm hoping to get a
assistance here in chat.  At anyrate, here is what I've managed to come up
with thus far.  I just wish I knew this stuff better.  At the moment I'm at
TWO scripts to create a state file necessary for checking (as I was before
when doing the test case with my 200+ lines of if-thens LOL).  And a test
case in every script in init.d.  I'd like to make this into a single
function as opposed to rewriting each script in init.d.  I've posted the two
check scripts below, but I'd like to condense those into one script as well.
First thing I need to do this, is a way to get the name of the currently
running script (preferably not the name of the symlink).  I thought about
using sed for the second commented line that should idealy contain '# Begin
/etc/rc.d/init.d/$ScriptName'  Of course, users will write their own init
scripts, and may or may not omit this line.  So, is there anyway to get the
name of the currently running script?  Even the symlink name would work, as
I could butcher it and get the name with ls -l, sed, and basename if needs
be.  The idea in itself seems to be more trouble than it's worth NOW, but at
the same time, I figure this a good way to learn about the tools I have at

Ideas? Suggestions?  Should I just drop it? lol



The scripts:

currently have two scripts in /etc/rc.d/init.d/

# Begin /etc/rc.d/init.d/rlstate
# The following lines to be used with /etc/rc.d/init.d/rltest to
# create a state file for checking validity of starts and stops
# in all runlevels.  /etc/rc.d/init.d/rltest simply calls this script
# with $(runlevel) as the argument.  the runlevel command
# returns two values on the same line which will become
# $1 and $2 respectively in the below script.
source /etc/rc.d/init.d/functions
rm -f /var/cache/rlstate > /dev/null
echo 'PRL='$1 >> /var/cache/rlstate
echo 'CRL='$2 >> /var/cache/rlstate
# End /etc/rc.d/init.d/rlstate

# Begin /etc/rc.d/init.d/rltest
/etc/rc.d/init.d/rlstate $(runlevel)
# End /etc/rc.d/init.d/rltest

and symlinks to rltest at S01rltest in RLs 1-5 and at K01rltest in RLs 0-6
so it's always current on a runlevel change.

Unsubscribe: send email to listar at
and put 'unsubscribe lfs-chat' in the subject header of the message

More information about the lfs-chat mailing list