Last active
August 29, 2015 14:13
-
-
Save briantissue/066587871f3abe3e6b77 to your computer and use it in GitHub Desktop.
Check Your Server Disks---Over 90% Utilization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#For checking disk space on our servers | |
#Clear Yesterday's Log | |
#Checking for root brought to you by Brad Arnold | |
if [ "$(whoami)" != "root" ]; then | |
echo "Not running as root. Exiting..." | |
echo "Please use sudo -s then run this script again as root." | |
exit 0 | |
else | |
echo "Running as root. Good" | |
fi | |
if [ -d "./disk_logs" ] | |
then | |
echo "Correct directory exists." | |
ls -lah | grep disk_logs | |
else | |
echo "Error: Directory ./disk_logs does not exist." | |
echo "Creating Directory Now...." | |
mkdir disk_logs | |
fi | |
echo "Clear yesterday's report and continue? [Y,n]" | |
read input | |
if [[ $input == "Y" || $input == "y" ]]; then | |
> ./disk_logs/disk_log.txt | |
else | |
echo "Stopping Script...." | |
exit 0 | |
fi | |
read -p "Press [Enter] key to check disk space on servers..." | |
echo "****************" >> ./disk_logs/disk_log.txt | |
echo "Server Disk Usage Report" >> ./disk_logs/disk_log.txt | |
echo "Today is $(date)" >> ./disk_logs/disk_log.txt | |
echo "****************" >> ./disk_logs/disk_log.txt | |
for HOST in `cat current_linux_server_ip_list|grep -v ^#`; do echo ${HOST}; ssh ${HOST} "hostname;df -h |grep -e '9[0-9]%'"; echo ""; done >> ./disk_logs/disk_log.txt | |
read -p "Press [Enter] key to finish, log file is located in disk_logs directory....." | |
#Will print to the local machines default printer | |
echo "Print this report? [Y,n]" | |
read input | |
if [[ $input == "Y" || $input == "y" ]]; then | |
lpr ./disk_logs/disk_log.txt | |
else | |
echo "Ok, you can still view the file though" | |
fi | |
echo "Email This Report To Linux Sys Admins? [Y,n]" | |
read input | |
if [[ $input == "Y" || $input == "y" ]]; then | |
echo "Disk Check $(date)" | mutt -a "./disk_logs/disk_log.txt" -s "Enterprise Disk Check" -- [email protected] | |
echo "Disk Check $(date)" | mutt -a "./disk_logs/disk_log.txt" -s "Enterprise Disk Check" -- [email protected] | |
echo "Disk Check $(date)" | mutt -a "./disk_logs/disk_log.txt" -s "Enterprise Disk Check" -- [email protected] | |
else | |
echo "This script is complete." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You'll need to create a file called 'current_linux_server_ip_list' with the IP addresses of the servers you would like to check.
Example:
192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4