2

I tried to display the list of startup scripts for the current runlevel at bootup. I wrote the following code.

rl=`runlevel | cut -d " " -f2`
ls /etc/rc.d/rc$rl.d/S* | cut -d "/" -f5
sleep 10

It's working if I put this code in rc.local file.

But it's not working if I put it in rc file or in a separate script file abc in /etc/init.d and by creating softlinks in runlevel directories.

But simple commands like follows are able to run in all the methods.

ls /etc/init.d

Do some commands like runlevel or piping won't work unless some of the scripts have started? Or is there something else?

And if I put my code in rc file, my code runs before and after reboot.

  • So what's the difference between rc, rc.local and rc.sysinit files?
  • Where exactly I need to edit those files?

Also I can find S99local -> softlink for rc.local in 2, 3, 4 and 5 runlevels.

Does it mean that rc.local won't run on runlevel 1?

5
  • rc is typically not used by Linux distributions but is used in BSD
  • rc.local is used to be able to execute additional commands during the startup without having to add symlinks.
  • rc.sysinit seems to be Red Hat specific and is executed very early in the process. It is executed as one of the first scripts while rc.local is executed later.

Also I can find S99local -> softlink for rc.local in 2,3,4 and 5 runlevels. Does it mean that rc.local won't run on runlevel 1?

Correct, that means that S99local which is a symlink to /etc/rc.local will be one of the last scripts executed when entering runlevels 2, 3, 4 and 5. It won't get executed for runlevel 1 as 1 is the single user runlevel, typically used for rescue/maintenance work.

  • rc.sysinit is often specified by /etc/inittab to be the first thing run by init. – MrMas Aug 3 '18 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.