Changes

Jump to: navigation, search

OPS245 Lab 1

361 bytes removed, 19:29, 14 June 2021
editing so that bash script doesn't redirect to file by default.
&#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/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/~ops245/labs/report.bash<br>&nbsp;https://ict.senecacollege.ca/~ops245/labs/report3.bash</span></code></b><br><br></li><li>Try to understand what these Bash Shell scripts do.</li></ol>

Navigation menu