2

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:

#!/bin/sh
#
# 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.

2
  • My Freinds , take care of formats before posting.
    – Raja G
    Dec 16, 2013 at 14:03
  • I suppose you mean all the files in /etc/rc0.d/ and /etc/rc6.d/.
    – jarno
    Dec 28, 2015 at 15:00

1 Answer 1

0

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.

2
  • Thank you Malte Skoruppa! Yes it was the $HOME variable. I found no shutdown.log in /root. Dec 16, 2013 at 14:33
  • Glad I could help! If it solved your problem, please consider marking the answer as accepted. Happy holidays to you :) Dec 16, 2013 at 14:35

You must log in to answer this question.

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