5

I am using Debian wheezy. My problem is, I am using a limited 2.5 GB net connection and would like to capture my usage before shutting down. My idea is simply running a script as:

#!/bin/bash
date >> ~/mydatausage.txt
ifconfig -a >> ~/mydatausage.txt

at the time of shutdown.

How can I run this script at shutdown, as root?

2 Answers 2

2

According to the following instruction

/etc/init.d/REDME
/etc/rc?.d/REDME

you need to put the script in /etc/init.d/ and make a symbolic link in /etc/rc0.d/ this corresponds to the shutdown runlevel and if you want to execute the script when rebooting then make a symbolic link in rc6.d. If you list the folder rc0.d then you will see the script starts with S or K. S come from Start if you want to run script and K come from Kill if you want to stop script

2
  • thanks for your answer ,can you improve the answer by direct instructions.
    – Raja G
    Commented Nov 3, 2013 at 5:23
  • It seems that this solution does not work anymore (I'm using Debian 8.7) Commented Apr 12, 2017 at 14:14
2

Put the script in /etc/rc0.d/ directory, make sure it has execute permissions, and follow the naming convention S*

In your case, you can save your above script in a file at /etc/rc0.d/S00myscript & make sure it is executable by running chmod +x /etc/rc0.d/S00myscript

2
  • can you improve the answer by direct instructions.
    – Raja G
    Commented Nov 3, 2013 at 5:23
  • Done. You can try the instructions now. Commented Nov 3, 2013 at 5:38

You must log in to answer this question.

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