It’s rather easy to run a command or a script on boot without going through the full Sys V style init stuff.
/etc/rc.local is executed after the init scripts on boot, but unlike BSD, Linux doesn’t have a
So how can we execute a command on shutdown? Usually,
/etc/init.d/halt is used for shutting down, which calls
/sbin/halt.local (if it exists). So we simply add our commands to
# echo "YOUR_COMMAND" >> /sbin/halt.local
Note that if the file does not exist, you have to add a shebang (e.g.
#!/bin/sh) and make it executable (
chmod +x /sbin/halt.local)