#!/bin/bash # ./lab2-check.bash # Author: Murray Saul # Date: May 22, 2016 # # Purpose: Check that students correctly installed all VMs correctly, # and that centos2 VM can connect correctly to the other VMs # via SSH # Function to indicate OK (in green) if check is true; otherwise, indicate # WARNING (in red) if check is false and end with false exit status function check(){ if eval $1 then echo -e "\e[0;32mOK\e[m" else echo -en "\e[0;31mWARNING:\e[m" echo $2 echo exit 1 fi } # end of check() function clear # Clear the screen # Make certain user is logged in as root if [ $USER != "root" ] then echo "Note: You are required to run this program as root." exit 1 fi # Start checking lab2 echo echo "CHECKING YOUR LAB2 WORK:" echo # Check centos2 VM was installed (correct hostname) echo -n "Checking correct hostname \"centos2\": " check "hostname | grep -iqs \"centos2\"" " This current VM does NOT have the hostname \"centos2\". Make certain that this VM is your centos2 VM. If it is and you didn't provide a proper hostname, then use the man-pages on the command called \"hostnamectl\" to set this the hostname to this VM as \"centos2\", and re-run this checking script." # Check centos2 VM has ext4 file-system echo -n "Checking \"centos2\" VM is using \"ext4\" file-system: " check "grep -iqs \"ext4.*/\" /etc/fstab" "This script did NOT detect the root \"/\" file-system type \"ext4\". Is it \"xfs\" instead? Then too bad, you were not following instructions: you need to delete this VM and create the \"centos2\" VM again with the correct file-system type, then download and re-run this checking script." # Check sshd service started and enable for centos2 echo -n "Checking sshd service running and enabled on \"centos2\" VM: " check "systemctl status sshd | grep -iqs \"active/\" && systemctl is-enabled sshd | grep -iqs \"enabled/\"" "This script noticed that either both sshd service is NOT running and NOT enabled, or ssd service is running, but is NOT enabled Please refer back to the lab instructions on how to run AND enable the sshd service, and then re-run this checking script. # Check iptables firewall exception is correctly set echo -n "Checking iptables is correctly set for centos2 VM: " check "iptables -L | grep -iqs \"x/\"" "This script noticed that your iptables (firewall) has not been set-up correctly. Please re-issue the \"iptables\" command and then have your professor or lab-monitor check your iptables settings, and then re-run this checking script" # Check yum update run on centos2 echo -n "Checking that yum update was run on \"centos2\" VM: " check "yum historyL | grep -iqs \"x/\"" "This script noticed that the \"yum update\" was NOT run on your \"centos2\" VM. Please run the yum update, and re-run this checking script." # Check myreport.bash script contained in /root/bin echo -n "Checking iptables is correctly set for centos2 VM: " check "iptables -L | grep -iqs \"x/\"" "This script noticed that your iptables (firewall) has not been set-up correctly. Please re-issue the \"iptables\" command and then have your professor or lab-monitor check your iptables settings, and then re-run this checking script" # Check that myreport.bash was run and created report in /root/report.txt echo -n "Checking that myreport.bash was run and created report in \"/root/report.txt\"" check "test -f \"/root/report.txt\"" "This script noticed that the file \"/root/report.txt\" deos not exist. Make certain to run the shell script you created, and then re-run this checking script." # Check that SELinux is disbled on centos2 VM echo -n "Checking that SELinux is disabled on \"centos2" VM:" check "grep -isq SELINUXTYPE=disabled /etc/selinux/config"" "This script noticed that SELinux has not been disabled on your current VM (centos2). Make certain to disable SELinux, then re-run this checking script." # Check centos2 VM can connect to centos1 VM via ssh echo -n "Checking that that your VM can connect to \"centos1\" VM via ssh" read -p "Enter your centos1 username (when prompted, enter your password for centos1 username): " centos1UserName read -p "Enter IP Address for your centos1 VMs eth0 device: " centos1_IPADDR check "ssh $centos1UserName@$centos1_IPADDR ls > /dev/null 2> /dev/null" "This script CANNOT connect to your \"centos1\" VM. There are a number of issues that can cause this. Call over your instructor or lab-monitor to help you troubleshoot this issue. Once this issue has been resolved, then re-run this checking script." # Check yum update run on centos1 VM echo -n "Checking that yum update was run on \"centos1\" VM: " check "ssh $centos1UserName@$centos1_IPADDR yum history | grep -iqs \"x/\"" "This script noticed that the \"yum update\" was NOT run on your \"centos1\" VM. Please run the yum update, and re-run this checking script." # Check centos2 VM can connect to centos3 VM via ssh echo -n "Checking that that your VM can connect to \"centos1\" VM via ssh" read -p "Enter your centos3 username (when prompted, enter your password for centos3 username): " centos3UserName read -p "Enter IP Address for your centos3 VMs eth0 device: " centos3_IPADDR check "ssh $centos3UserName@$centos3_IPADDR ls > /dev/null 2> /dev/null" "This script CANNOT connect to your \"centos3\" VM. There are a number of issues that can cause this. Call over your instructor or lab-monitor to help you troubleshoot this issue. Once this issue has been resolved, then re-run this checking script." # Checking centos 3 for correct fs types for the partitions created echo -n "Checking \"centos3\" VM is using \"ext4\" file-system: " check "ssh $centos3UserName@centos3_IPADDR grep -iqs \"ext4.*/\" /etc/fstab" "This script did NOT detect the root \"/\" file-system type \"ext4\". Is it \"xfs\" instead? Then too bad, you were not following instructions: you need to delete this VM and create the \"centos3\" VM again with the correct file-system type, then download and re-run this checking script." # Checking that SELinux is disabled on centos3 VM echo -n "Checking that SELinux is disabled on \"centos3\" VM" check "ssh $centos3UserName@$centos3_IPADDR | grep -isq SELINUXTYPE=disabled /etc/selinux/config > /dev/null 2> /dev/null" "This script notices that you HAVE NOT disabled SELinux on your \"centos3\" VM. Please disable SELinux on the \"centos3\" VM, and re-run this checking script." # Check yum update run on centos3 VM echo -n "Checking that yum update was run on \"centos3\" VM: " check "ssh $centos3UserName@$centos3_IPADDR yum history | grep -iqs \"x/\"" "This script noticed that the \"yum update\" was NOT run on your \"centos3\" VM. Please run the yum update, and re-run this checking script." # Checking centos4 for network connectivity echo -n "Checking that that your VM can connect to \"centos1\" VM via ssh" read -p "Enter your centos4 username (when prompted, enter your password for centos4 username): " centos4UserName read -p "Enter IP Address for your centos4 VMs eth0 device: " centos4_IPADDR check "ssh $centos4UserName@$centos4_IPADDR ls > /dev/null 2> /dev/null" "This script CANNOT connect to your \"centos4\" VM. There are a number of issues that can cause this. Call over your instructor or lab-monitor to help you troubleshoot this issue. Once this issue has been resolved, then re-run this checking script." # Checking centos 4for correct fs types for the partitions created echo -n "Checking \"centos2\" VM is using \"ext4\" file-system: " check "ssh $centos4UserName@$centos4_IPADDR grep -iqs \"ext4.*/\" /etc/fstab" "This script did NOT detect the root \"/\" file-system type \"ext4\". Is it \"xfs\" instead? Then too bad, you were not following instructions: you need to delete this VM and create the \"centos2\" VM again with the correct file-system type, then download and re-run this checking script." # Checking that SELinux is disabled on centos4 VM echo -n "Checking that SELinux is disabled on \"centos4\" VM" check "ssh $centos4UserName@$centos4_IPADDR | grep -isq SELINUXTYPE=disabled /etc/selinux/config > /dev/null 2> /dev/null" "This script notices that you HAVE NOT disabled SELinux on your \"centos4\" VM. Please disable SELinux on the \"centos4\" VM, and re-run this checking script." # Check yum update run on centos4 echo -n "Checking that yum update was run on \"centos4\" VM: " check "ssh $centos4UserName@$centos4_IPADDR yum history | grep -iqs \"x/\"" "This script noticed that the \"yum update\" was NOT run on your \"centos4\" VM. Please run the yum update, and re-run this checking script." echo echo echo "Congratulations! That certainly was a lot of checking!" echo echo "You have completed your lab2. Please check SIGN-OFF section" echo "To setup your terminals and command output, etc. to show your" echo "OPS235 instructor for SIGN-OFF." echo