Using sed - Part 2


  1. Log in to users.cs.umb.edu
    You will need an ssh client to do this.

  2. Go to your it341 directory
        cd it341
  3. Create a directory for this assignment
        mkdir assign4
  4. Go to your assign4 directory
        cd assign4
  5. Copy practice files to this directory
        cp  /home/ckelly/course_files/it341_files/{interfaces,hosts,passwd} .
    The scripts you will write below will operate on the files you have just copied.
  6. Create script files in this directory
        touch {interfaces,hosts,passwd}_update.sh
  7. Do a long listing to confirm that script files exist:
        ls -l *_update.sh
  8. Make script files executable:
        chmod 750 *_update.sh
  9. Open the shell script interfaces_update.sh for editing:
    The first line of your shell script should be the hashbang line: #!/bin/bash

    Next, add sed commands that will make the following modifications to the interfaces file you have just copied
    • Change the line
          iface  eth0  inet  dhcp
      to read
          iface  eth0  inet  static
    • Add the following after this line
          network  10.0.0.0
          address  10.0.0.201  
          gateway  10.0.0.1
          broadcast  10.0.0.255
          netmask  255.255.255.0
          dns-nameservers  10.0.0.1
    If you need to debug/troubleshoot your shell script, please re-copy the interfaces from /home/ckelly/course_files/it341_files so that you have a fresh copy to test against.
  10. Open the shell script hosts_update.sh for editing:
    The first line of your shell script should be the hashbang line: #!/bin/bash

    Next, add sed commands that will add the following lines to hosts
        # Gateway
        10.0.0.1    it20.it.cs.umb.edu  it20
        
        # Addresses for the Windows PCs
        10.0.0.240  it21.it.cs.umb.edu it21
        10.0.0.241  it22.it.cs.umb.edu it22
        10.0.0.242  it23.it.cs.umb.edu it23
        10.0.0.243  it24.it.cs.umb.edu it24
        10.0.0.244  it25.it.cs.umb.edu it25
        10.0.0.245  it26.it.cs.umb.edu it26
        10.0.0.246  it27.it.cs.umb.edu it27
        10.0.0.247  it28.it.cs.umb.edu it28

    If you need to debug/troubleshoot your shell script, please re-copy the hosts from /home/ckelly/course_files/it341_files so that you have a fresh copy to test against.
  11. Open the shell script passwd_update.sh
    The first line of your shell script should be the hashbang line: #!/bin/bash

    Next, add sed commands that will modify the line
        sysadmin:x:1000:1000:sysadmin,,,:/home/sysadmin:/bin/bash
    so it reads
        sysadmin:x:1000:1000:sysadmin,,,:/home.it20/sysadmin:/bin/bash
    NOTE: Multiple lines in the passwd file may contain home, but your script should be written so that it is changed ONLY on the line for sysadmin. If you need to debug/troubleshoot your shell script, please re-copy the passwd from /home/ckelly/course_files/it341_files so that you have a fresh copy to test against.

Script Behavior Example:

The following images are intended to illustrate how your scripts would behave. The example I am using here will involve the files interfaces and interfaces_update.sh

Grading Script:

(This is not the exact script I will use, but it is a good indicator of how one should be able to run your script.)
#!/bin/bash


# Each iteration or repetition of this loop represents 
# the process of grading ONE student's work

for student in `ls ~/it341`
do
    
    # Here, I bring in pristine copies of the text
    # files, copy over your script files, and 
    # and make them executable

    mkdir $student
    cd $student
    cp /home/ckelly/course_files/it341_files/* .
    cp ~/it341/$student/assign4/*.sh .
    chmod 755 *.sh

    # Check, print, and run interfaces_update.sh

    ls -l interfaces_update.sh
    cat interfaces_update.sh
    echo Running interfaces_update.sh
    ./interfaces_update.sh

    # Confirm that expected changes were made to
    # the interfaces file

    ls -l interfaces
    cat interfaces

    # Check, print, and run hosts_update.sh

    ls -l hosts_update.sh
    cat hosts_update.sh
    echo Running hosts_update.sh
    ./hosts_update.sh

    # Confirm that expected changes were made
    # to the hosts file

    ls -l hosts
    cat hosts

    # Check, print, and run passwd_update.sh

    ls -l passwd_update.sh
    cat passwd_update.sh
    echo Running passwd_update.sh
    ./passwd_update.sh

    # Confirm that expected changes were made
    # to the passwd file

    ls -l passwd
    cat passwd

done