Open main menu

CDOT Wiki β

Changes

OPS235 Lab 3 - CentOS7

262 bytes added, 12:14, 25 April 2015
no edit summary
We will continue with using shell scripts to create a Software Information Report that manipulates output generated by the '''rpm''' command. The '''sed''' and '''awk''' commands are very useful tools in shell scripting to manipulate text. In this lab, we will be using ''sed'' to allow the user to select certain portions from the rpm command (options -qi).
 
If you require <u>'''additional practice'''</u> in additional shell scripts skills, run the commands in your '''Matrix''' account: <ul><li>'''N/A'''</li></ul>
 
Perform the following steps in your c7host machine:
# Open a Bash shell terminal and login as root.
<code style="color:#3366CC;font-family:courier;font-size:.9em;margin-left:20px;">
<br>
::&#35;!/bin/bash <br>::<br>::::&#35; packageInfo.bash<br>::&#35; Purpose: Generates a report to displaying specified information of installed software<br>::&#35;<br>&#35; USAGE: ./packageInfo.bash<br>::&#35;<br>::&#35; Author: *** INSERT YOUR NAME ***<br>::&#35; Date: *** CURRENT DATE ***<br>::<br>::::if [ $HOME != "root" ] # only runs if logged in as root<br>::then<br>&nbsp;echo "You must be logged in as root." >&2<br>::&nbsp;exit 1<br>::fi<br>
</code>
<br>
<code style="color:#3366CC;font-family:courier;font-size:.9em;">
::if [ $# -ne 1 ]<br>::then<br>:: &nbsp; echo "Your command must have a application-name as argument" >&2<br>:: &nbsp; echo "USAGE: $0 [application-name]" >&2<br>:: &nbsp; exit 1<br>::fi<br><br>::&#35; Creates Create 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 <br>::echo -e "Date: $(date +'%A %B %d, %Y (%H:%M:%p)')\n\n " >> /root/package-info.txt<br>
</code>
<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;+<br>::Available Package Information Items:<br><br>::Name<br>::Summary<br>::Version<br>::License<br>::Source<br>::URL<br>::+<br>::read -p "Enter word(s) shown above separated by spaces: " choice<br><br>::&#35; Convert spaces to pipe symbol (|)<br>::processedChoice=$(echo $choice | sed 's/ /|/g')<br><br>::&#35; Use sed with extended regular expressions to only print those matching report elements<br>::rpm -qi $1 | sed -r -n "/($processedChoice)/ p" &gt;&gt; /root/package-info.txt<br><br>::cat &lt;&lt;+<br>::File "/root/package-info.txt" can been created<br>::+<br>
</code>
13,420
edits