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.

derHugo
  • 3,356
  • 5
  • 31
  • 51

1 Answers1

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.

Malte Skoruppa
  • 13,196
  • 5
  • 57
  • 65