Question
Using sed - Part 2 Each team member must complete this assignment individually in his or her own it341 directory. This project will not be
Using sed - Part 2
Each team member must complete this assignment individually in his or her own it341 directory.
This project will not be done on your virtual machine.
Instead, it will be done on users.cs.umb.edu.
When I say "script" in this assignment, I am referring to something very different from the script utility, as used in Assignment #3.
The first line of each script file should be a "shebang" line:
#!/bin/bash
To make file changes in place, use sed with the -i option. Example:
sed -i 's/Roses/Poinsettias/' roses.txt
Rather than printing the change to standard output, it will change the file itself.To create a backup when changing a file, specify an extension for the backup file with the -i option. Example:
sed -i.bak 's/Roses/Poinsettias/' roses.txt
In addition to changing the file, the new file roses.txt.bak will contain the file's old contents.My grading process will include the following:
Copy pristine file copies into a folder.
Print the text of your script files.
Run the scripts.
Print the text files to verify their contents have changed.
You may see (a variation of) my grading script at the bottom of this page.
For another example, see the file roses_example.pdf
To be sure that these scripts work, you will likely need to run and test them multiple times. Each time, you should download new copies of the text files before testing your scripts.
NOTE: This assignment assumes that you are familiar with the process of writing and running bash scripts.
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 copiedChange 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.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.
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started