Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've read the answers to this and similar questions already, but so far none had worked for me.

On my Ubuntu 11.10 (oneiric) system, all the files in /etc/rc0.d/ and /etc/rc0.d/ are links. I put my script (called *shutdown_script*) in the /etc/init.d/ directory and created two symbolic links to it, one in /etc/rc0.d/ and the other in /etc/rc6.d, both with the name *K99shutdown_script*. The script is not being run at shutdown, which is what I want. The script is just to test if I could run a script at shutdown; I supply the code in shutdown_script below:

# Tests script to run at shutdown.
# Script creates a fil and writes to it. 
# Usage: ./shutdown-script

touch $HOME/shutdown.log
echo "Shutting down at `date` ..." >> $HOME/shutdown.log

As you can see, it just adds a file to the home folder showing the current date and time.

Please could you tell me what I may be doing wrong, and more importantly, how to get a script to run at shutdown.

share|improve this question
My Freinds , take care of formats before posting. – Raja Dec 16 '13 at 14:03
I suppose you mean all the files in /etc/rc0.d/ and /etc/rc6.d/. – jarno Dec 28 '15 at 15:00
up vote 0 down vote accepted

In principle what you are doing is correct. My guess is you may be looking in the wrong place for that shutdown.log file you are trying to create. Since these scripts will be executed at shutdown by root, the variable $HOME will not point to your usual home directory. See if /root/shutdown.log has been created, or supply an absolute path in your script without the $HOME variable.

share|improve this answer
Thank you Malte Skoruppa! Yes it was the $HOME variable. I found no shutdown.log in /root. – Fahal Marraas Dec 16 '13 at 14:33
Glad I could help! If it solved your problem, please consider marking the answer as accepted. Happy holidays to you :) – Malte Skoruppa Dec 16 '13 at 14:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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