Changes

Jump to: navigation, search

OPS235 Lab 3

541 bytes added, 14:53, 22 December 2018
LAB 3 SIGN-OFF (SHOW INSTRUCTOR)
|colspan="3" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;padding-left:20px;"|Linux Command Reference<br>
H
|- valign="top"
| style="padding-left:20px;"|Archiving / Compiling
[http://man7.org/linux/man-pages/man1/tar.1.html tar]<br>
[http://unixhelplinuxcommand.ed.ac.ukorg/CGIlc3_man_pages/man-cgi?gzip gzip1.html gzip, gunzip]<br>
[http://man7.org/linux/man-pages/man1/make.1.html make]<br><br>
Software Manangement<br>
[httphttps://wwwlinux.rpmdie.orgnet/man/max-rpm8/rpm.8.html rpm]<br>
[http://man7.org/linux/man-pages/man8/yum.8.html yum]
| style="padding-left:20px;"|Miscellaneous
| style="padding-left:20px;"|Matrix On-line Tutorials:<ul><li>Shell Scripting Basics - Part 4 (The sed Utility):<br>'''/home/murray.saul/scripting-4'''</li></ul>
|}
 
= INVESTIGATION 1: TROUBLESHOOTING BOOTING &amp; FORGOTTEN ROOT PASSWORD =
#To restart in graphical mode, simply enter the command <b><code><span style="color:#3366CC;font-size:1.2em;">reboot</span></code></b>.
{{Admon/important | What To Do If Reboot Doesn't Work | In this mode, the reboot command may not work. If it doesn't, go to the top of the centos1 VM window, select Send Key -> Ctrl+Alt+Delete.}}
===Catastrophic Boot Problems===
'''Perform the following steps:'''
#Boot up your '''centos3''' VM.H
#Change your working directory to '''/usr/share/doc/sudo*'''
#Use the tar (tape archiver) command to create an archive file named "/tmp/archive1.tar" by issuing the following command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">tar cvf /tmp/archive1.tar .</span></code></b>
#Compare '''/tmp/extract1/README''' and '''/usr/share/doc/sudo*/README'''. Are they exactly the same? Why?
#Create the directory '''/tmp/extract2'''
#Move the file '''archive2.tgztar.gz''' to the '''/tmp/extract2''' directory.#Extract the files from the second archive by issuing the following command: <b><code><span style="color:#3366CC;font-size:1.2em;">tar xvzf /tmp/extract2/archive2.tar.gz</span></code></b>
#Note that this time a separate <b><code><span style="color:#3366CC;font-size:1.2em;">gunzip</span></code></b> command was not needed. Why?
#Repeat the previous command, leaving out the option '''z'''. Does it work? Why?
'''Answer Investigation 2 observations / questions in your lab log book.'''
 
=INVESTIGATION 3: MANAGING SOFTWARE PACKAGES=
'''Perform the following steps:'''
#Make certain that you are in your '''c7host''' VMmachine.
#Issue the command: <b><code><span style="color:#3366CC;font-size:1.2em;">yum install elinks</span></code></b>
#Now issue the command: <b><code><span style="color:#3366CC;font-size:1.2em;">yum info elinks</span></code></b>
<ol>
<li value="11">We will now look at how we can add different repositories to our '''c7host''' machine.</li><li>As root, issue the following command: <b><code><span style="color:#3366CC;font-size:1.3em;">yum repolist</span></code></b></li><li>Take a few moments to view the contents of the file. Do you see which repositories are used by the '''yum''' command? Write down the repositories in your lab logbook.</li><li>View the following link to see a general listing of repositories:<br>[ [http://wiki.centos.org/AdditionalResources/Repositories Available Repositories for Centos] ].</li><li>To add the epel repository, issue the command:<br><b><code><span style="color:#3366CC;font-size:1.3em;">sudo yum install epel-release</span></code></b></li><li>To verify that you have added the repository, you can issue the command: <b><code><span style="color:#3366CC;font-size:1.3em;">yum repolist</span></code></b></li><li>Unused and unneeded software can present a security risk and ties up disk space needlessly. Find '''at least 4 other packages''' to remove on your c7host machine(for example: '''sound & video''', '''games''', etc) that you're not using on your system. Be careful to ensure that removing those packages does not also remove other software that you do need.</li>
</ol>
# Go to an appropriate webpage and download a "zipped tarball" (compressed source code) for the '''lbreakout2''' game (filename should be something like: '''lbreakout2.tar.gz''')
#Change to the directory where you downloaded that file (most likely ''~/Download''s).
# Use the '''tar''' command to compress decompress the "zipped tarball" called something like (not may be exactly): '''lbreakout2.tar.gz'''.
# Change to the directory that contains that ''lbreakout2'' source code.
{| width="40%" align="right" cellpadding="10"
<li>Issue the following command to install the files for application development by issuing the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">yum groupinstall "Development Tools"</span></code></b></li>
<li>Issue the command in step 7. You should get another ERROR! What dependency is missing?</li>
<li>Issue the following command to install the library files for SQL by issuing the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">yum install SDL-devel</span></code></b>(possibly <b><code><span style="color:#3366CC;font-size:1.2em;">yum install libpng-devel</span></code></b> and <b><code><span style="color:#3366CC;font-size:1.2em;">yum install zlib-devel</span></code></b> )</li>
<li>Reissue the <b><code><span style="color:#3366CC;font-size:1.2em;">./configure && make</span></code></b> command. Where you successful?</li>
<li>Run the command <b><code><span style="color:#3366CC;font-size:1.2em;">lbreakout</span></code></b>(or possibly '''lbreakout2'''). Where you successful?</li> <li>You need to run a command to make this program available regardless of your current directory (as opposed to running command in the directory that contains the program). Login as root (be sure to be in the same directory as the source code after logging in as root) and issue the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">make install</span></code></b></li> <li>Run the command: <b><code><span style="color:#3366CC;font-size:1.2em;">lbreakout</span></code></b> . Did it work? Issue the command:<br> <b><code><span style="color:#3366CC;font-size:1.2em;">which lbreakout</span></code></b>. What do you think that the '''make install ''' command did?</li>
</ol>
{{Admon/tip|Bash Shell Scripting Tips:|<br>'''<u>The Here Document</u>'''<br><ul><li>A neat little trick involving a special type of redirection of stdin symbol: '''&lt;&lt;''' that allows input to be redirected to a command from within the command.<br><br> </li><li>Examples:<br><br>''cat &lt;&lt;+<br>This is a test message<br>This is the second line<br>+''<br><br>''mail -s "test message" youremailaddr &lt;&lt;+<br>This is a test message<br>I hope you like it.''<br>+<br><br>''tr [a-z] [A-Z] &lt;&lt;+<br>i like ops235<br>i love scripting.<br>+''<br><br></li></ul>'''<u>Using sed to Manipulate Text</u>'''<ul><li>The Linux command '''sed''' stands for <u>'''S'''</u>treaming <u>'''Ed'''</u>itor which is an effective way to manipulate a text file, output sent from a command, or from within a "here document". This command can manipulate matching text on a variety of criteria (such as '''line number(s)''', '''regular expression match''', etc). Commands can then be used for manipulation such as '''omitting''', '''printing''', '''substituting''', '''adding''', and '''inserting''' text.<br><br></li><li>The sed option '''-n''' suppresses display of text so the print ('''p''') command can be used; otherwise, the text will be displayed (with edits via the sed command instructions).<br><br></li><li>Results of text manipulation with sed can be stored in a variable using command substitution, or redirected to a file. '''NEVER redirect the stdout from a sed command to the same input file (or the input file will be destroyed)!''' <br><br></li><li>Examples<br><br>''sed 's/&#124;/ /g' &lt;&lt;+<br>I&#124;like&#124;weekends!<br>+''<br><br>''sed 's/$/\n/g' &lt;&lt;+<br>This text<br>should be<br>double-spaced!''<br>+<br><br></li></ul>}}
|}
 
===Part 3: Generating Sofware Package Information with Shell Scripts===
We will continue with using shell scripts to create a Software Information Report that manipulates output generated by the '''rpm''' command. The '''sed''' and '''awk''' commands are very useful tools in shell scripting to manipulate text. In this lab, we will be using ''sed'' to allow the user to select certain portions from the rpm command (options -qi).
# Use your '''c7host''' VM for this section.
# Open a Bash shell terminal and login as root.
# Use a text editor (such as <b><code><span style="color:#3366CC;font-size:1.2em;">vi</span></code></b> or <b><code><span style="color:#3366CC;font-size:1.2em;">nano</span></code></b>) to create a Bash Shell script called: <b><code><span style="color:#3366CC;font-size:1.2em;">packageInfo.bash</span></code></b> in the '''/root/bin ''' directory.
# Enter the following text content into your text-editing session:
<code style="color:#3366CC;font-family:courier;font-size:.9em;margin-left:20px;font-weight:bold;">
&#35; Date: *** CURRENT DATE ***<br>
<br>
if [ $HOME PWD != "/root/bin" ] # only runs if logged in as /root/bin directory<br>
then<br>&nbsp;echo "You must be logged in as root." >&2<br>
&nbsp;exit 1<br>
<br>
&#35; Use sed with extended regular expressions to only print those matching report elements<br>
rpm -qi $1 | sed -r -n "/^($processedChoice)/ p" &gt;&gt; /root/package-info.txt<br>
<br>
cat &lt;&lt;+<br>
<ol>
<li value="8">Save, set permissions, and then run that shell script for the application '''gedit'''. Did it create that report? Try running the script without an argument - What did it do? <li>Use the <b><code>wget</code></b> command to download, study, and run the following shell scripts on-line:<blockquote><b><code><span style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">httpshttp://scscs.senecac.onsenecacollege.ca/~murray.saulops235/lab3/packageInfoGraphical.bash</span></code></b></blockquote></li><li>Try to understand what this Bash Shell script does.</li><li>You have completed lab3. Proceed to Completing The Lab, and follow the instructions for "lab sign-off".</li></ol>
'''Answer the Investigation 3 observations / questions in your lab log book.'''
# Switch to your <u>'''c7host'''</u> machine, open a shell terminal, and login as root.
# Change to the directory: '''/root/bin'''
# Issue the Linux command: <b><code><span style="color:#3366CC;font-size:1.2em;">wget http://matrixcs.senecac.onsenecacollege.ca/~murray.saulops235/ops235lab3/lab3-check.bash</span></code></b>
# Give the '''lab3-check.bash''' file execute permissions (for the file owner).
# Run the shell script and if any warnings, make fixes and re-run shell script until you receive "congratulations" message.
#Arrange proof of the following on the screen:<br><span style="color:green;font-size:1.5em;">&#x2713;</span> '''centos3''' VM:<blockquote><ul><li> Archived files '''created'''</li><li>Archive files '''restored'''</ul></blockquote><span style="color:green;font-size:1.5em;">&#x2713;</span> '''c7host''' Machine:<blockquote><ul><li> '''One repository added''' for yum</li><li>Run the '''lab3-check.bash''' script in front of your instructor (must have all <b><code><span style="color:#66cc00;border:thin solid black;font-size:1.2em;">&nbsp;OK&nbsp;</span></code></b> messages)</li></ul></blockquote><span style="color:green;font-size:1.5em;">&#x2713;</span> '''Lab3''' log-book filled out.
 
= Practice For Quizzes, Tests, Midterm &amp; Final Exam =

Navigation menu