running a script at shutdown
James Gray
james at gray.net.au
Sun Jun 15 21:01:48 UTC 2008
On 16/06/2008, at 6:08 AM, Dirk Tamme wrote:
> Hi,
> I have a small script (looking for some file properties etc.). I
> checked that it works, and now I want to run it automatically at
> every shutdown. I think this should be possible -- but how to manage
> this?
>
> Thanks for any help,
> Dirk T.
Drop it into /etc/rc0.d with a name like "SnnMyScript" where "nn" is a
number. This will cause it to run as the nn'th item when entering run
level 0 (ie, shutdown).
However, the "proper" way would be to drop the script into /etc/init.d/
MyScript then use "sudo update-rc.d" to insert your script at the
correct places:
sudo update-rc.d MyScript start nn 0
Again, where "nn" is the order you want to run your script at. If you
want it to run on BOTH shutdown and reboot (run levels 0 and 6
respectively) append "6" to the upate-rc.d line above. Be careful
about where you run your script (the "nn") as it may rely on services
that get stopped during shutdown/reboot. Conversely, your script's
changes may be over-written by a process after your script has run.
Without knowing more about your script, all I can say is make sure you
know what it relies on and get the "nn" right :)
HTH,
James
More information about the ubuntu-users
mailing list