Changes

Jump to: navigation, search

OPS235 Lab 3

282 bytes added, 14:53, 22 December 2018
LAB 3 SIGN-OFF (SHOW INSTRUCTOR)
| 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===
#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>
<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).
<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