How to Run Commands at Shutdown on Linux
Linux and Unix systems have long made it pretty easy to run a command on boot. Just add your command to
/etc/rc.local and away you go. But as it turns out, running a command on shutdown is a little more complicated.
Why would you want to run a command as the computer shuts down? Perhaps you want to de-register a machine or service from a database. Maybe you want to copy data from a volatile storage system to a permanent location. Want your computer to post "#RIP me!" on its Twitter account before it shuts down?
Read more at OpenSource.com