Itis 3100 Apache Lab




Download 36,92 Kb.
bet4/10
Sana15.03.2017
Hajmi36,92 Kb.
#53
1   2   3   4   5   6   7   8   9   10

Script two:


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

Then create the following script named go:




#!/bin/bash

IFILE=/etc/network/interfaces

ifdown eth0

if test $1 = "static" ; then

cp $IFILE.static $IFILE

echo "Static interfaces loaded!"

elif test $1 = "dhcp" ; then

cp $IFILE.dhcp $IFILE

echo "DHCP interfaces loaded!"

else


echo "Parameter must be static or dhcp"

fi

ifup eth0


To run the script:



**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.


#!/bin/bash

IFILE=/etc/network/interfaces

if test $# -ne 2 ; then

echo "Two parameters must be passed, the state and the NIC id"

exit 1

fi

ifdown $2



cp $IFILE.$1 $IFILE

ifup $2


**Document the working and one of the tests with a bad parameter.


Summary:

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.



Download 36,92 Kb.
1   2   3   4   5   6   7   8   9   10




Download 36,92 Kb.