Changes

Jump to: navigation, search

OPS245 Lab 1

223 bytes removed, 19:29, 14 June 2021
editing so that bash script doesn't redirect to file by default.
| |[[Image:ssd.png|thumb|left|175px|<b>Solid State Drive</b><br>Minimum Size: 250GB]]
| [[Image:log-book.png|thumb|left|100px|<b>[[:Media:OPS235_logbook.pdf|Lab Logbook]]</b><br>(lab 1)]]
| style="padding-left:15px;" |Package Management
&#35; Create report title<br>
<br>
echo "SYSTEM REPORT" > /root/report.txt<br>echo "Date: $(date +'%A %B %d, %Y (%I:%M %p)')" >> /root/report.txt<br>echo >> /root/report.txt<br>
</code>
<br>
<ol><li value="13">Save and run the bash shell script (remember to use sudo to run it as root). View You should see the contents of output printed to your screen. Use a file redirection <b>&gt;</b> to save the output into a 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;">
echo "Hostname: $(hostname)" >> /root/report.txt<br>echo >> /root/report.txt<br>echo "Kernel Version: $(uname -rv)" >> /root/report.txt<br>echo >> /root/report.txt<br>
</code>
<br>
<ol><li value="15">Save, run the script(redirecting the output once again), 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="19">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/~ops245/lab1labs/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/~ops245/lab1labs/report.bash<br>&nbsp;https://ict.senecacollege.ca/~ops245/lab1labs/report3.bash</span></code></b><br><br></li><li>Try to understand what these Bash Shell scripts do.</li></ol>
'''Answer Investigation 3 observations (all parts and questions) in your lab log book.'''
:'''Perform the Following Steps:'''
<ol>
<li>Install python3 on your Centos Host machine.Open a terminal and type:</li><code style="color:#3366CC;font-family:courier;font-size:.9em;margin-left:20px;font-weight:bold;">sudo yum install python3</code>
<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 permissions to run this script. We will correct this in lab 2.</li>
# 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/~ops245/labchecklabs/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, the file generated by the lab1-check.bash script, your logbook, and your myreport.py to blackboard.
= Practice For Quizzes, Tests, Midterm &amp; Final Exam =

Navigation menu