Skip to content

Instantly share code, notes, and snippets.

@brockers
Last active December 14, 2018 06:26
Show Gist options
  • Save brockers/2deeb94a78515ec2f3ef54ff3c014501 to your computer and use it in GitHub Desktop.
Save brockers/2deeb94a78515ec2f3ef54ff3c014501 to your computer and use it in GitHub Desktop.
Quick script to check Linux Class Quiz
#!/bin/bash
SERVER="$2"
USER="$1"
mprint(){
MESSAGE="$1"
echo "===================== $MESSAGE ============================"
}
echo ""
echo ""
echo "========================================================================"
echo " Checking server $SERVER"
echo "========================================================================"
# Command to look for word ubuntu on remote os-release file
# ssh "$USER"@"$SERVER" cat /etc/os-release |grep ubuntu|wc -l
# take the output of a command and put it into a variable
# IS_UBUNTU=$(somecommand)
# combine them and we get:
IS_UBUNTU=$(ssh "$USER"@"$SERVER" cat /etc/os-release |grep -c ubuntu)
mprint "Is System Updated"
ssh "$USER"@"$SERVER" sudo dnf -y update
mprint "Did We Install packages"
# Check out installed packages
if [[ $IS_UBUNTU -gt 0 ]]; then
HTTPD="apache2"
ssh "$USER"@"$SERVER" dpkg -l "$HTTPD" wget vim
else
HTTPD="httpd"
ssh "$USER"@"$SERVER" rpm -q monit tmux curl
fi
mprint "SELinux Status"
ssh "$USER"@"$SERVER" sudo getenforce
ssh "$USER"@"$SERVER" sudo cat /etc/selinux/config
# Check our shared folders and permissions
mprint "List BLock Devices and RAID Arrays"
ssh "$USER"@"$SERVER" lsblk
# Check RAID Configuration
ssh "$USER"@"$SERVER" sudo mdadm --detail /dev/md0
#Check out users and groups
# ssh "$USER"@"$SERVER" groups employees managers
mprint "List Group Properties"
ssh "$USER"@"$SERVER" sudo getent group administrators
ssh "$USER"@"$SERVER" sudo getent group powerusers
ssh "$USER"@"$SERVER" sudo getent group users
mprint "Groups for known admins"
ssh "$USER"@"$SERVER" sudo groups azimmerman banderson
mprint "Total Size of Users File"
ssh "$USER"@"$SERVER" sudo wc /etc/passwd
mprint "Check for passwords"
ssh "$USER"@"$SERVER" sudo getent shadow wwagner
ssh "$USER"@"$SERVER" sudo getent shadow wsnyder
mprint "Check Folder Permissions"
# Check our shared folders and permissions
ssh "$USER"@"$SERVER" sudo ls -al /shared/
ssh "$USER"@"$SERVER" sudo ls -al /home/shared/
mprint "Check CRONJOB Status"
ssh "$USER"@"$SERVER" sudo ls -l /etc/cron.d
ssh "$USER"@"$SERVER" sudo cat /etc/cron.d/*
ssh "$USER"@"$SERVER" sudo cat /etc/crontab
mprint "Did we install checkinstall"
ssh "$USER"@"$SERVER" sudo which checkinstall
mprint "User Script"
# Check script
ssh "$USER"@"$SERVER" sudo ls -alh /usr/bin/makeflags.sh
ssh "$USER"@"$SERVER" sudo cat /usr/bin/makeflags.sh
mprint "Web Server Status"
# Check out web server status
# shellcheck disable=SC2029
ssh "$USER"@"$SERVER" systemctl status "$HTTPD"
ssh "$USER"@"$SERVER" ls -al /var/www/html
firefox "$SERVER" & # And says keep runing and return CMD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment