#!/bin/bash ################################### #Name: Lab2Check1.sh #Purpose: Script that checks the first part of OPS235 - Lab 2 (Seneca College) #Written by: Philip Ianni #Last Edited: 18 January 2016 ################################## #Ensure root if [[ $(whoami) != "root" ]] then echo "Please run this as root!" exit 1 fi #Decare important variables to make easy to manage in future ImageDir="/var/lib/libvirt/images/" ImageList=$(ls $ImageDir) RequiredImages=("centos1.img" "centos2.img" "centos3.img") #Create banner echo " ####################################################### PART ONE - THREE | Check Images #######################################################" #For loop to check if each image is present for image in ${RequiredImages[@]} do if [[ $(echo ${ImageList[@]} | grep $image) ]] then printf "\033[0;32mOK\033[0m - $image exists in /var/lib/libvirt/images/\n" else printf "\033[0;31mOK\033[0m - $image does not exist in /var/lib/libvirt/images/\n" fi done #Check for backups in regular user's home folder echo " ######################################################## Investigation 2: PART ONE - TWO | Check Backups ########################################################" #Quick test to see if user actually exists until [[ $continue = yes ]] do read -p "Please enter the userID of the regular user: " user if [[ $(grep ${user}:x: /etc/passwd) ]] then continue=yes else echo "User does not seem to exist! Try again" fi done #Check the user's home directory for gzipped files BackupList=$(ls /home/$user) for image in ${RequiredImages[@]} do if [[ $(echo "${BackupList[@]}" | grep "${image}\.backup\.gz") ]] then printf "\033[0;32mOK\033[0m - ${image}.backup.gz exists in /home/${user}\n" else printf "\033[0;31mPROBLEM\033[0m - $image.backup.gz does not exist in /home/${user}\n" fi done