Using sed - Part 2
- Log in to users.cs.umb.edu
You will need an ssh client to do this.
- Go to your it341 directory
cd it341
- Create a directory for this assignment
mkdir assign4
- Go to your assign4 directory
cd assign4
- 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.
- Create script files in this directory
touch {interfaces,hosts,passwd}_update.sh
- Do a long listing to confirm that script files exist:
ls -l *_update.sh
- Make script files executable:
chmod 750 *_update.sh
- 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
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.
- 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.
- 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
- This just shows an example of you creating your directory for this assignment, changing into it, and copying over the relevant files:
- Editing interfaces_update.sh and setting the permissions to 750. You may have already set the permissions to 750, before editing, in which case you would not need to set them again:
- This shows what the interfaces file would look like before running the interfaces_update.sh script -- and after. Notice how the file-size and the last-modified date on the interfaces file have changed!
- This shows the contents of the interfaces file, which you see has changed as a result of running the interfaces_update.sh script:
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