Here are the 10 files you will need. 1) \"colors\" red blue green light red ligh
ID: 3603954 • Letter: H
Question
Here are the 10 files you will need.
1) "colors"
red blue green
light red light blue light green
dark green dark red
2) "course_directory"
/courses/it244/f13/ghoffmn
3) "day"
day
I am looking for daylight
night and day
day after day after day
4) "fox"
The quick brown fox
jumped over
the lazy dogs.
5) "hosts"
127.0.0.1 localhost
6) "interfaces"
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
7) "letters_digits"
abcd 1234 5678
8) "new_night"
nite
this is a new line
night
nighty night night
night and day
day and night
all the live long night
night after night after night
9) "night"
nite
night
nighty night night
night and day
day and night
all the live long night
night after night after night
10) "passwd"
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:13:13:proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh
list:x:38:38:Mailing List Manager:/var/list:/bin/sh
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
libuuid:x:100:101::/var/lib/libuuid:/bin/sh
syslog:x:101:103::/home.ORIG/syslog:/bin/false
mysql:x:102:105:MySQL Server,,,:/nonexistent:/bin/false
messagebus:x:103:106::/var/run/dbus:/bin/false
proxy:x:13:13:proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh
list:x:38:38:Mailing List Manager:/var/list:/bin/sh
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
libuuid:x:100:101::/var/lib/libuuid:/bin/sh
syslog:x:101:103::/home.ORIG/syslog:/bin/false
mysql:x:102:105:MySQL Server,,,:/nonexistent:/bin/false
messagebus:x:103:106::/var/run/dbus:/bin/false
bind:x:105:110::/var/cache/bind:/bin/false
sysadmin:x:1000:1000:sysadmin,,,:/home/sysadmin:/bin/bash
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:
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:
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.
Create and go to your it341/assign5 directory:
Copy practice files to this directory
The scripts you will write below will operate on the files you have just copied.Create the script interfaces_update.sh
Write a shell script using sed commands that will make the following modifications to the interfaces file you have just copyChange the line
to read
Add the following after this line
Create the shell script hosts_update.sh
Write a shell script using sed commands that will add the following lines to hosts
Create the shell script passwd_update.sh
Write a shell script using sed commands that will modify the line
so it reads
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.
Explanation / Answer
interfaces_update.sh
#!/bin/bash
sed -i.bak 's/dhcp/static/' interfaces.txt
sed '$ a network 10.0.0.0' interfaces.txt
sed '$ a address 10.0.0.201' interfaces.txt
sed '$ a gateway 10.0.0.1' interfaces.txt
sed '$ a broadcast 10.0.0.255' interfaces.txt
sed '$ a netmask 255.255.255.0' interfaces.txt
sed '$ a dns-nameservers 10.0.0.1' interfaces.txt
Here, 's/dhcp/static/’ replaces occurrence of ‘dhcp’ with ‘static’. To append lines in the end $ is used followed by ‘a’ which means append which is followed by string to be added.
hosts_update.sh
#!/bin/bash
sed -i.bak -e '$ a # Gateway' interfaces.txt
sed -i.bak -e '$ a 10.0.0.1 it20.it.cs.umb.edu it20' hosts.txt
sed -i.bak -e '$ a ' hosts.txt # inserts blank line
sed -i.bak -e '$ a # Addresses for the Windows PCs ' hosts.txt
sed -i.bak -e '$ a 10.0.0.240 it21.it.cs.umb.edu it21' hosts.txt
sed -i.bak -e '$ a 10.0.0.241 it22.it.cs.umb.edu it22' hosts.txt
sed -i.bak -e '$ a 10.0.0.242 it23.it.cs.umb.edu it23' hosts.txt
sed -i.bak -e '$ a 10.0.0.243 it24.it.cs.umb.edu it24' hosts.txt
sed -i.bak -e '$ a 10.0.0.244 it25.it.cs.umb.edu it25' hosts.txt
sed -i.bak -e '$ a 10.0.0.245 it26.it.cs.umb.edu it26' hosts.txt
sed -i.bak -e '$ a 10.0.0.246 it27.it.cs.umb.edu it27' hosts.txt
sed -i.bak -e '$ a 10.0.0.247 it28.it.cs.umb.edu it28' hosts.txt
passwd_update.sh
#!/bin/bash
sed -i.bak -e 's/sysadmin:x:1000:1000:sysadmin,,,:/home/sysadmin:/bin/bash/sysadmin:x:1000:1000:sysadmin,,,:/home.it20/sysadmin:/bin/bash' passwd.txt
‘s/old/new’ if old and new itself contain ‘/’ then each / should escaped by .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.