0

I need your help with bash script that I’m trying to build. To keep things simple I will make it short:

The script starts running once it’s gets to run level 5 so i copied the script to /etc/rc.d/rc5.d/S99fix And it should look like this:

init 3

# Do some stuff…

init 5

rm –rf /etc/rc.d/rc5.d/S99fix

The problem is that when I reboot the machine and it gets to runlevel 5 it starts the script by running the init 3 command but there it ends… I’m killing my own script before its time. the Do some stuff, init 5, rm -rf doesn't run. Is there a way I can do what I want to do and still switch between runlevels without killing my script while doing so?

Just to add some details to this question...

  • I'm using SLES 11.2
  • i'm installing and configuring nvidia drivers so doing stuff in runlevel 3 is required.
  • This research started as a way to do stuff to the X server while in runlevel 3 and bring it back to runlevel 5. I presume there is an option just to stop and start the xdm service. But now I've become interested to understand if switching between runlevel 3 and 5 is possible in bash script.
1
  • 4
    What is the goal that you are trying to achieve? I bet there is a better way to achieve your goals than starting up to runlevel 5, go back down to 3, and back up to 5 again.
    – replay
    Dec 31, 2013 at 7:04

2 Answers 2

1

You can, and did, change the runlevel from a bash script. But it doesn't make sense to change the runlevel from a script that runs on a runlevel change! Switching the runlevel kills your script because it's part of the setup of the previous runlevel.

Whatever you need to do regarding NVidia drivers, it is not related to being in runlevel 3. Maybe you need to do things before starting the X server? In this case, do it either during startup (runlevel S) or in the startup for the runlevel you intend to reach, but before running xdm.

0

I suspect it would work. During runlevel changes, init may kill all alive processes, including your bash process.

You should see which script that init runs (after a runlevel change), and add your hooks there.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .