I'm trying to find out which is the name of the service script that is running at startup. I need the name for calling the default script afterwards.
I can't assume the name in advance, that's why I have to get it during its execution.
NAME=${0##*/}
SCRIPTNAME=/etc/init.d/$NAME
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
I've tried differents approaches:
- Use $BASH_SOURCE
- Use basename $0
- Use bash specific var ${0##*/}
All of them works if I run the script manually from a shell but not after a restart. I suppose that init.d launch process in a different way.
I'm using Debian Lenny (I know, quite old...) and bash v3.2.39. I'm opened to use other type of shell if necessary.
Thanks.