Changes

Jump to: navigation, search

OPS245 Lab 1

2,527 bytes added, 22:15, 22 January 2021
Part 1: Using VMware Workstation Pro to Create a New Virtual Machine (VM)
[[Image:Format_ExFAT.png|thumb|right|250px|'''Format drive window''' in order to format your new SSD as '''exFAT''' ('''Windows''')]]
{{Admon/caution|If you are using an external drive: FORMAT YOUR External SSD AS exFAT|'''You ''must'' format your external drive as exFAT.'''<br>By default, most external drives will be formatted for NTFS. <u>'''NTFS-formatted drives will cause issues in this course!'''</u> When you plug your drive in, open My Computer, right-click on the new drive, and select ''Format...''.<br />If you are storing the vmdk file on your machine's internal storage, this is not necessary.}}
{{Admon/important|Confirm External SSD Device is Recognized as a Drive in Windows Explorer|It is essential that your Windows machine recognizes your SSD device with a drive letter on your Windows machine. You may experience problems if you are using the Kingston SSD. If so, then run '''diskmgmt.msc''' in order to create a volume and format your disk1.}}
{{Admon/caution|ATTENTION| PRIOR to proceeding, you MUST perform the following step <u>BEFORE</u> starting your Host VM in order to allow your Host VM to run correctly!!!<br>Students that do not follow these procedures exactly will run in to problems when trying to perform lab2 !!! You have been warned!!!.}}
<br><br>
# <ol><li value="27">Make certain that your Host VM is <u>'''NOT'''</u> powered on before proceeding!</li># <li>In the right-hand window (below "c7host"), and below ''"Power on this virtual machine"'', click the link called '''Edit virtual machine settings'''.</li># <li><span style="background-color:yellow">In this setup dialog box, click the '''options''' tab and then click the '''Advanced''' option at the bottom of the list. On the right-hand side, under ''Firmware Type'', '''select the radio button for UEFI'''. Then click on the '''Hardware''' tab, and then select the '''CD/DVD (IDE)''' device and select in the right-side select the radio button for the '''use ISO Image file'''. Click the '''Browse''' button and specify the path of your downloaded CentOS 7 Full install DVD (most likely file is contained in your Downloads folder). Click '''Processors''', and click the check-box to <u>enable</u> '''Virtual Intel VT-X/EPT or AMD-V/RVI'''. When finished, click on the '''OK''' button</span>.</li># <li>You will return to your c7host VM. Click '''Power on this virtual machine''' icon near the top to boot your c7host VM to start your c7host VM, and proceed to Part 2.</li></ol>
===Part 2: Install CentOS on your Newly-Created VM ===
&#35;<br>&#35; USAGE: ./myreport.bash<br>
<br>
if [ $USER (whoami) != "root" ] # only runs if not logged in as root<br>
then<br>&nbsp;echo "You must be logged in as root." >&2<br>
&nbsp;exit 1<br>
</code>
<br>
<ol><li value="9">Save your editing session, assign the '''myreport.bash''' file read and execute permissions (at least for the owner) and run by typing:<br><b><code><span style="color:#3366CC;font-size:1.2em;">./myreport.bash</span></code></b></li><li> Did it work?</li><li>Run it again with <b><code><span style="color:#3366CC;font-size:1.2em;">sudo ./myreport.bash</span></code></b></li><li>Reopen your text-editing session for '''/root~/bin/myreport.bash''' and add the following lines of code to the bottom of the shell script file:</ol>
<br>
<code style="color:#3366CC;font-family:courier;font-size:.9em;font-weight:bold;">
<br>
echo "SYSTEM REPORT" > /root/report.txt<br>
echo "Date: $(date +'%A %B %d, %Y (%HI:%M:%p)')" >> /root/report.txt<br>
echo >> /root/report.txt<br>
</code>
<br>
<ol><li value="813">Save and run the bash shell script (remember to use sudo to run it as root). View the contents of the file called '''report.txt''' that was generated (I hope you are using the up arrow key to issue previously issued commands in order to save time!). Notice how the redirection symbol &gt; is used at the beginning of the report, and then the other redirection symbol &gt;&gt; is used to help "grow" the report with the other content.</li><li>The only remaining content of the report would be the system information. We can use a shell scripting trick called "command substitution" $( .. ) in order place results from an command to be used by another command (like echo). Re-edit the shell script and add the following code at the bottom of the shell script file:</li></ol>
<br>
<code style="color:#3366CC;font-family:courier;font-size:.9em;font-weight:bold;">
</code>
<br>
<ol><li value="1015">Save, run the script, and view the ''report.txt'' contents (are you using tip that was given to save time?).</li><li>Edit the shell script and include output from the <b><code><span style="color:#3366CC;font-size:1.2em;">ps aux</span></code></b> and <b><code><span style="color:#3366CC;font-size:1.2em;">ip address show</span></code></b> commands (with appropriate titles). Remember to redirect that output to add to the bottom of the file!</li><li>Save, run and confirm that the shell script is working correctly.</li><li>What would be the use of keeping this shell script as a Linux system administrator?</li></ol><ol><li value="1419">Here are some more "complex" Bash Shell scripts, that perform the same task. Although you are not required to understand some of these other tricks, it is recommended that you view the contents of the scripts and save them for future consideration or examples.</li><li>The <b><code>wget</code></b> command can be used to quickly download files from the Internet. Issue the following command:<br><b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">wget https://ict.senecacollege.ca/~ops235peter.callaghan/ops245/labs/text-report.bash</span></code></b></li><li>Verify that the file '''text-report.bash''' was downloaded to your current directory.</li><li>Assign read and execute permissions for this file by issuing the command: <b><code><span style="color:#3366CC;font-size:1.2em;">chmod u+rx text-report.bash</span></code></b></li><li>Run this Bash Shell script by issuing the command: <b><code><span style="color:#3366CC;font-size:1.2em;">./text-report.bash</span></code></b></li><li>Check to see if it created a report in your current directory. What is the purpose of the report?</li><li>Use the <b>vi</b> text editor to view the contents of the file <b>text-report.bash</b>. Can you understand how this script works?<br><br></li><li>Use the <b><code>wget</code></b> command to download, study, and run the following shell scripts on-line:<br><b><code><span style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">https://ict.senecacollege.ca/~ops235/labs/report.bash<br>&nbsp;https://ict.senecacollege.ca/~ops235/labs/report3.bash</span></code></b><br><br></li><li>Try to understand what these Bash Shell scripts do.</li><li>You have completed lab1. Proceed to Completing The Lab, and follow the instructions for "lab sign-off".</li></ol>
'''Answer Investigation 3 observations (all parts and questions) in your lab log book.'''
= INVESTIGATION 4: Using Python Scripting to Generate System Information Reports =
Before we can successfully automate parts of configuration using python, we need to learn how to use it. Initially we will duplicate tasks we have already learned how to do in bash. This way can learn how the language works as we go.
 
In this investigation you will write a python script that duplicates (as closely as possible with the parts of python we have covered so far) the bash script from the previous investigation.
 
:'''Perform the Following Steps:'''
<ol>
<li>Install python3 on your Centos Host machine.</li>
<li><ul><li>Create a new file in your ~/bin directory called '''myreport.py'''</li>
<li>Since we haven't covered if statements in python yet, we won't be able to check if the user running the script is root. For now, we will have to trust ourselves to remember to use elevated permisisons to run this script. We will correct this in lab 2.</li>
</ul></li>
<li>Populate the beginning of the file with sh-bang line and block comment equivlent to what was in '''myreport.bash'''
<code style="color:#3366CC;font-family:courier;font-size:.9em;margin-left:20px;font-weight:bold;">
<br>
&#35;!/usr/bin/env python3<br>
<br>
&#35; Author: *** INSERT YOUR NAME ***<br>
&#35; Date: *** CURRENT DATE ***<br>
&#35;<br>
&#35; Purpose: Creates system info report<br>
&#35;<br>&#35; USAGE: ./myreport.py<br>
</code>
</li>
<li>Add a line that will print out the heading '''System Report'''<br />
<code style="color:#3366CC;font-family:courier;font-size:.9em;margin-left:20px;font-weight:bold;">
print('System Report')
</code>
</li>
<li>Save your script and run it. Does it work?</li>
<li>You'll notice that the python script is currently sending its output to your terminal. Since we haven't covered how to write to a file yet, this is ok for now. Just use output redirection on the command line when you run the script to send the output to '''~/pythonreport.txt'''.</li>
<li>Add the extra commands for your python script to also output (with appropriate headings):
<ul>
<li>The current date.</li>
<li>The hostname of the machine.</li>
<li>The kernel version.</li>
<li>The list of all processes.</li>
<li>The IP address.</li>
</ul>
</li>
<li>Run your script to make sure it works. Note that the output does not need to match the bash script exactly, but it should be very close.</li>
</ol>
= LAB 1 SIGN-OFF (SHOW INSTRUCTOR) =
Follow the submission instructions for lab 1 on Blackboard.
# Make certain that your '''c7host''' VM is running, open the Bash Shell terminal.<br><br>
# Change to the '''~/bin''' directory.<br><br>
#Download the checking script by issuing the following Linux command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">wget https://ict.senecacollege.ca/~ops235peter.callaghan/ops245/labs/lab1-check.bash</span></code></b><br><br>
# Give that downloaded shell script file execute permissions (for the file owner).<br><br>
# Run the shell script using sudo and if there are any warnings, make fixes and re-run shell script until you receive a "congratulations" message.<br><br>
::<span style="color:green;font-size:1.5em;">&#x2713;</span> Proof that c7host VM is set for '''virtualization''' (Refer to: '''INVESTIGATION 1''' - '''Part 1''' - '''Step #29''')
#Take a screenshot of the evidence and upload it and , the file generated by the lab1-check.bash script , and your myreport.py to blackboard.
= Practice For Quizzes, Tests, Midterm &amp; Final Exam =

Navigation menu