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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: