How can I execute a script on shutdown

For certain reasons you may want to do some tasks before shutdown to change some settings for when you startup again. In my case when I’m in a local network I need a static IP, but when I start linux from outside this lan I need DHCP setup. So every time I shutdown I change it to DHCP. To do that you should create a script and put it on /etc/rc2.d/ directory:

touch /etc/rc2.d/dhcp.local

### dhcp.local ###
#!/bin/bash
sudo sh -c "echo \"auto lo\niface inet loopback\" > /etc/network/interfaces"

See ya