4

As I asked in the title, I'm looking for a script/command to find the correct directory (usually /etc/init.d or /etc/rc.d/init.d). Right now I'm using

    dirname `find / -name acpid 2> /dev/null | grep /etc/`

but sometimes I get more than one result (probably some of the results are link) . Any suggestion?

I'm using acpid because it is a script that should be present in almost every distribution that is not prehistoric. If someone has a suggestion for a better script, let me know, thanks :)

l3golas
  • 107
  • 9
  • Which flavor of Linux are you using? – Tyler Jandreau Feb 04 '13 at 11:58
  • I'm using Ubuntu, Debian, RedHat Enterprise, Fedora, CentOS, SuSE and other distros. – l3golas Feb 04 '13 at 12:13
  • 1
    It is perfectly legitimate and normal to have the same script appear in multiple places; a single script may be used in various phases of startup and shutdown. They can be links — symbolic or hard. And the names in the active `rc.N` (for n in 0..6) directories can be prefixed with a number so that they are executed in sequence — at least, in the prehistoric systems I used to work with. – Jonathan Leffler Feb 04 '13 at 15:05
  • Thanks Jonathan. What you say is perfectly normal, because in each runlevel (identified by a directory of the type rcN.d) there's a script to start or kill every init script. Anyway I'm searching just the script, not the links that refer to it. So the question is, again: is it normal that the same script (not the links) is in more directories? Which one is the right one? – l3golas Feb 04 '13 at 15:20

1 Answers1

3

I believe that your approach is quite good as the location of the startup scripts is distro-dependable. Simply add -type f option to exclude links from your results.

INITDIR=`find / -type f -name acpid 2> /dev/null | grep /etc/`
KBart
  • 1,580
  • 10
  • 18