#!/bin/bash

# check-assn1-p1.bash

# Author: Murray Saul
# Created: January 20, 2017  Revised: May 25, 2019

# Purpose: To generate data to be mailed to OPS335 instructor in order
#          to mark second portion of OPS335 assignment #1 - Part 1

# Error-checking prior to running shell script
# Check that user is logged on as root

if [ `id -u` -ne 0 ]
then
  echo "You must run this shell script as root" >&2
  exit 1
fi

# Check that mailx application has been installed

if ! which mailx > /dev/null 2> /dev/null 
then
  echo "You need to run \"yum install mailx\" prior to running this shell script" >&2
  exit 1
fi

if ! virsh list | grep -iqs concept
then
  echo "You need to run your cloning-source \"concept\" VM" >&2
  exit 2
fi



# Prompt for username and Full name

read -p "Please enter YOUR FULL NAME: " fullName

read -p "Please enter YOUR SENECA LOGIN USERNAME: " userID



# Generate Evaluation Report

echo "Assignment 1 (Part 1) Evaluation Report - Date: $(date +'%A %B %d, %Y @ %H:%M:%S %P')" > a1p1-eval.txt
echo >> a1p1-eval.txt
echo >> a1p1-eval.txt
echo "VM hostname: $(ssh root@172.21.5.100 hostname)" >> a1p1-eval.txt
echo >> a1p1-eval.txt
echo "yum update performed: $(ssh root@172.21.5.100 yum check-update && echo updated)" >> a1p1-eval.txt
echo >> a1p1-eval.txt
echo "Users other than root: $(ssh root@172.21.5.100 ls /home)" >> a1p1-eval.txt
echo >> a1p1-eval.txt
echo "SELinux status: $(ssh root@172.21.5.100 grep -i SELINUX.*=.*disabled /etc/selinux/config)" >> a1p1-eval.txt
echo >> a1p1-eval.txt
echo "Firewalld Status:" >> a1p1-eval.txt
ssh root@172.21.5.100 systemctl status firewalld | egrep -i "(active|stop)" >> a1p1-eval.txt
echo >> a1p1-eval.txt
echo "iptables Status:" >> a1p1-eval.txt
ssh root@172.21.5.100 systemctl status iptables | egrep -i "(active|stop)" >> a1p1-eval.txt
echo >> a1p1-eval.txt
echo "iptables activity (all chains):" >> a1p1-eval.txt
ssh root@172.21.5.100 iptables -L -v >> a1p1-eval.txt
echo >> a1p1-eval.txt
echo "Cloning source can connect to Internet" >> a1p1-eval.txt
echo "ping 8.8.8.8 Status" >> a1p1-eval.txt
ssh root@172.21.5.100 ping -c 3 8.8.8.8 >> a1p1-eval.txt
echo >> a1p1-eval.txt
echo "Network configuration parameters" >> a1p1-eval.txt
ssh root@172.21.5.100 cat /etc/sysconfig/network-scripts/ifcfg-eth0 >> a1p1-eval.txt
echo >> a1p1-eval.txt
echo "PermitRootLogin Status: $(ssh 172.21.5.100 grep -i ^permitrootlogin /etc/ssh/sshd_config)" >> a1p1-eval.txt
echo >> a1p1-eval.txt
echo "Shell Script contents (/root/bin/assnBackup.bash):" >> a1p1-eval.txt
cat /root/bin/assnBackup.bash >> a1p1-eval.txt
echo >> a1p1-eval.txt
echo "Full Backup Status (/backup/full/):" >> a1p1-eval.txt
ls -l /backup/full/ >> a1p1-eval.txt
echo >> a1p1-eval.txt
echo "Crontab Log (/var/log/cron):" >> a1p1-eval.txt
cat /var/log/cron >> a1p1-eval.txt
echo >> a1p1-eval.txt
echo "Incremental Backup (/backup/incremental/cloning-source):" >> a1p1-eval.txt
ls -l /backup/incremental/cloning-source >> a1p1-eval.txt


# Send report information to instructor

cat > message.txt <<+
If you have received this e-mail message, then
you have successfully submitted the remaining
information for your OPS335 assignment 1 (part 1)

+



mail -s "OPS335-a1p1-$fullName"	ahad.mammadov@senecacollege.ca < a1p1-eval.txt
mail -s "OPS335-a1p1-confirmation" "$userID@myseneca.ca"  < message.txt

rm  a1p1-eval.txt message.txt 2> /dev/null

cat <<+

Submission of OPS335 assignment 1 (part 1) completed.
A confirmation message should have been sent to your
Seneca email account. If you did NOT receive a confirmation
message, please check that you install the mailx package,
check your junk or clutter email folder, or otherwise,
contact your OPS335 instructor.

+







