LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Mandriva (https://www.linuxquestions.org/questions/mandriva-30/)
-   -   Shutdown script (https://www.linuxquestions.org/questions/mandriva-30/shutdown-script-282676/)

Hexane 01-26-2005 08:43 PM

Shutdown script
 
Is there some script some where that gets called before the computer shuts down. I want to add something simple to save my total download/upload amounts by grabing them from /proc/net/dev before the computer turns off every time.

leonscape 01-26-2005 08:56 PM

You can install a script in your runlevel 0, and run level 6, to capture them.

Hexane 01-26-2005 09:03 PM

Where do I do that? some where in like /etc/init*?

Hexane 01-26-2005 09:05 PM

wait... /etc/rc0.d and /etc/rc6.d do I just add it in there?

leonscape 01-26-2005 09:22 PM

There's another directory /etc/init.d you put the script in there. Something like

Code:

#!/bin/sh
case "$1" in
    start )
        #Put your code here
    ;;
    stop|restart|status )
        echo "This script does not do anything for $1"
    ;;
    * )
        echo "usage:$0 {start|stop|restart|status}"
        exit 1
    ;;
esac

Then create two symlinks one in /etc/rc0.d and one in /etc/rc6.d with

cd /etc/rc0.d
ln -s ../init.d/scriptname S10scriptname
cd ../rc6.d
ln -s ../init.d/scriptname S10scriptname

The numbers are low in case anything that is shutdown by a script later thats required is still there.

Edit: also don't forget to make the script executable
chmod +x scriptname

bunnadik 01-27-2005 01:41 AM

Quote:

The numbers are low in case anything that is shutdown by a script later thats required is still there
Except the two scripts that turn everything off are run as S00... and S01... i.e. before that script.
So you probably want to rename them to something higher than 10 or it won't work.
Code:

mv /etc/rc6.d/S00killall  /etc/rc6.d/S11killall && /etc/rc6.d/S01reboot  /etc/rc6.d/S12reboot
mv /etc/rc0.d/S00killall  /etc/rc0.d/S11killall && /etc/rc0.d/S01halt  /etc/rc0.d/S12halt

- Peder

leonscape 01-27-2005 07:57 PM

Thats weird mine are set too 90, so what happens to all the stuff that needs shutting down on Madrake? They just get killed?

bunnadik 01-28-2005 01:36 AM

That's what the "K" entries are for (IIRC). When changing runlevel the system first runs the K(ill) entries in the new runlevel
(I've got 21 of them in rc0.d). Then it "starts" the S ones.

Thinking of that Hexane perhaps have to put his script in K30 or something depending on if K90network clears some entries.

- Peder


All times are GMT -5. The time now is 06:14 PM.