Changes

Jump to: navigation, search

OPS235 Lab 4 - CentOS7

3,833 bytes added, 17:34, 10 April 2015
no edit summary
# Open a Bash shell terminal and login as root.
# Use a text editor (such as <b><code><span style="color:#3366CC;font-size:1.2em;">vi</span></code></b> or <b><code><span style="color:#3366CC;font-size:1.2em;">nano</span></code></b>) to create a Bash Shell script called: <b><code><span style="color:#3366CC;font-size:1.2em;">backupVM.bash</span></code></b> in /root's home directory.
# Enter the following text content into your text-editing session:
<code style="color:#3366CC;font-family:courier;font-size:.9em;margin-left:20px;">
<br>
::&#35;!/bin/bash
::
::
::&#35; packageInfo.bash
::&#35; Purpose: Generates a report to displaying specified information of installed software
::&#35;<br>&#35; USAGE: ./packageInfo.bash
::&#35;
::&#35; Author: *** INSERT YOUR NAME ***
::&#35; Date: *** CURRENT DATE ***
::
::
::if [ $HOME != "root" ] # only runs if logged in as root
::then<br>&nbsp;echo "You must be logged in as root." >&2
::&nbsp;exit 1
::fi
</code>
<br>
<ol><li value="4">Save your editing session, but remain in the text editor.</li><li>The code displayed below will require the user to include only one argument after the command (script) which will be the application name. The following code will also generate the report title and current date. Add the following code</li></ol>
<br>
<code style="color:#3366CC;font-family:courier;font-size:.9em;">
::if [ $# -ne 1 ]
::then
:: &nbsp; echo "Your command must have a application-name as argument" >&2
:: &nbsp; echo "USAGE: $0 [application-name]" >&2
:: &nbsp; exit 1
::fi<br><br>
::&#35; Creates report title (echo with -e option allows newline \n character to be used)<br><br>
::echo -e "\nSOFTWARE PACKAGE INFORMATION REPORT" > /root/package-info.txt
::echo -e "Date: $(date +'%A %B %d, %Y (%H:%M:%p)')\n\n " >> /root/package-info.txt
 
</code>
<ol><li value="6">Save your editing session, but remain in the text editor.</li><li>The code displayed below uses a trick called the "Here Document" to redirect stdin from within the command (a quick way to display output on the screen). The read command will store the different information report items as words (separated by a space). The sed command used to convert the spaces to pipes (|) and stored into another variable. This allows the sed command to use extended regular expressions to print rpm elements that match those various patterns to be added to the report. Add the following code</li></ol>
<br>
<code style="color:#3366CC;font-family:courier;font-size:.9em;">
::&#35; Clear screen and use Here Document to display select on report items to read into variable<br><br>
::cat &lt;&lt;+
::Available Package Information Items:
 
::Name
::Summary
::Version
::License
::Source
::URL
::+
::read -p "Enter word(s) shown above separated by spaces: " choice<br><br>
::&#35; Convert spaces to pipe symbol (|)
::processedChoice=$(echo $choice | sed 's/ /|/g')<br><br>
::&#35; Use sed with extended regular expressions to only print those matching report elements
::rpm -qi $1 | sed -r -n "/($processedChoice)/ p" &gt;&gt; /root/package-info.txt<br><br>
::cat &lt;&lt;+
::File "/root/package-info.txt" can been created
::+
</code>
 
<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;">https://scs.senecac.on.ca/~murray.saul/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 Investigation 3 observations / questions in your lab log book.'''
13,420
edits

Navigation menu