Changes

Jump to: navigation, search

OPS235 Lab 3 - CentOS7

594 bytes removed, 06:18, 8 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 certqain certain portions from the rpm command (options -qi).
# 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 # Forces script to run in the bash shell
::
::
::&#35; backupVMpackageInfo.bash::&#35; Purpose: Creates system info Generates a reportto displaying specified information of installed software::&#35;<br>&#35; USAGE: ./reportpackageInfo.bash
::&#35;
::&#35; Author: *** INSERT YOUR NAME ***
</code>
<br>
<ol><li value="4">Save your editing session, but remain in the text editor.</li><li>This shell script is designed particularly for your centos1, centos2, and centos3 VMS.</li><li>The code displayed below will prompt require the user if they wish for all VMs to include only one argument after the command (script) which will be backed-up; otherwise, allow the user application name. The following code will also generate the option of specifying which VMs to be backed-upreport title and current date. Add the following code</li></ol>
<br>
<code style="color:#3366CC;font-family:courier;font-size:.9em;">
:: read -p "Backup all VMs? (y|n):" answer # prompt if all VMs to be backed-up::::if [ "$answer" = "y" # -ne 1 ] # Backup all VMs if answer is yes
::then
::&nbsp;for num in 1 echo "Your command must have a application-name as argument" >&2 3 # Determinant loop for 3 arguments: 1, 2, and 3::&nbsp;do::&nbsp;&nbsp;echo "Backing up VM #USAGE: $num0 [application-name]"::>&nbsp;&nbsp;gzip < /var/lib/libvirt/images/centos$num.img > /root/centos$num.img.backup.gz2::&nbsp;&nbsp;echo "VM #$num BACKUP DONE"exit 1::&nbsp;donefi
::elif [ "$answer" = "# Create report title (echo with -e option allows newline \n" ]character to be used)::then::&nbsp;read echo -p e "Which VM should be backed up? (1/2/3): \nSOFTWARE PACKAGE INFORMATION REPORT" numanswer::&nbsp;until echo $numanswer | grep "^[123]$" >> /devroot/null # Look for match of single digit: 1,2, or 3::&nbsp;do::&nbsp;&nbsp;read package-p "Invalid Selectioninfo. Select 1, 2, or 3: " numanswer::&nbsp;donetxt ::&nbsp;echo -e "Backing up VM #Date: $numanswer"(date +'%A %B %d, %Y (%H:%M:&nbsp;gzip < /var/lib/libvirt/images/centos$numanswer.img %p)')\n\n " >> /root/centos$numanswer.img.backup.gz::&nbsp;echo "VM #$numanswer BACKUP DONE":::else::&nbsp;echo "Invalid Selection.package-info.. Aborting program"::&nbsp;exit 2::fitxt
</code>
13,420
edits

Navigation menu