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?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Raja G
  • 5,749
  • 12
  • 44
  • 67

2 Answers2

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

Chirag Bhatia - chirag64
  • 2,720
  • 1
  • 20
  • 16
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

andr3w
  • 86
  • 2