This script will copy one of two preconfigured interfaces templates to interfaces. The two templates are interfaces.static and interfaces.dhcp. The script will be called go.sh and will have one parameter which will be either "static" or "dhcp". When the script is run it will stop the NIC, copy the appropriate file to interfaces, then restart the NIC.
First make two copies of interfaces:
Change to the networks file: cd /etc/network
Create the templates:
cp interfaces interfaces.static
cp interfaces interfaces.dhcp
Edit both templates with the values you wish to have in them
**Document the script working and not working (bad parameter)
Here is an alternate version (go2) that does not use an if clause and has a second parm for the NIC. This version checks for the correct number of parameters, but does not check their value. It assumes they have been typed in correctly. Create the script, make sure it is executable, and then test it. Try it with no parameters, with the correct parameters, then with statics spelled wrong, and then finally with the wrong NIC interface, e.g. eth9.
if test $# -ne 2 ; then
echo "Two parameters must be passed, the state and the NIC id"
cp $IFILE.$1 $IFILE
**Document the working and one of the tests with a bad parameter.
Scripts can make repetitive tasks easier. Scripts by convention end in .sh, but that is for human use only. The permissions for the script must be eXecutable for the owner, group or world to run them. The scripts go and go2 have no extension and they work perfectly well.