932
edits
Changes
m
Adding python investigation
</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;">
'''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>
#!/usr/bin/env python3<br>
<br>
# Author: *** INSERT YOUR NAME ***<br>
# Date: *** CURRENT DATE ***<br>
#<br>
# Purpose: Creates system info report<br>
#<br># 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.
::<span style="color:green;font-size:1.5em;">✓</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 & Final Exam =