Last active
December 20, 2017 05:03
-
-
Save mansurali901/4aed46a1263f3971a425 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
## This is an open Source script written for Optimize Linux Box. | |
## Author Mansur ul hasan | |
## Email [email protected] | |
clear | |
#<!------------- Notification Setting function | |
notification_func(){ | |
echo > /usr/local/cron/emailtemplates | |
if [ ! -f "/usr/local/cron/smart-disk-scanner/emaillist" ]; then | |
read -p "Enter the Email Address for notification : " email | |
echo $email > /usr/local/cron/smart-disk-scanner/emaillist | |
fi; | |
} | |
#<!----- Information gathering menu for Disks | |
info_grab_func(){ | |
intn=`ifconfig |awk '{print $1}' |head -n1` | |
ipinfo=`ifconfig $intn | awk '{print $2}' |grep addr | cut -d':' -f2` | |
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output; | |
do | |
echo $output | |
usep=$(echo $output | awk '{print $1}' | cut -d'%' -f1 ) | |
partition=$(echo $output | awk '{print $2}' ) | |
if [ "$usep" -ge "97" ]; then | |
hostname=$(hostname) | |
useemail=$(cat /usr/local/cron/smart-disk-scanner/emaillist) | |
ipinfo=`ifconfig eth0 | awk '{print $2}' |grep addr | cut -d':' -f2` | |
echo $ipinfo | |
echo " | |
%% SYSTEM DISK INFORMATION %% | |
|------------------------------------------------------------------------------| | |
| DATE : $(date) | |
| | |
| SERVER NAME : $(hostname) | |
| | |
| Partiotion : $partition | |
| | |
| Used Space : ($usep%) | |
|------------------------------------------------------------------------------| | |
Hey System Admins Please check the Servers Disk....!!! | |
---------------------------------------------------------------------- | |
Note : To unsubscribe this mailing list please contact NASA Department | |
---------------------------------------------------------------------- | |
This monitoring system is the part of Linux Genius v1.1 | |
For suuport please do contact at [email protected] | |
" >/usr/local/cron/smart-disk-scanner/emailtemplates | |
for em in `cat /usr/local/cron/smart-disk-scanner/emaillist` | |
do | |
mailx -r [email protected] -s "Linux Genius Alert Host $hostname : Disk space reached to $usep%" $em < /usr/local/cron/smart-disk-scanner/emailtemplates | |
mailx -r [email protected] -s "Linux Genius Alert Host $hostname : Disk space reached to $usep%" [email protected] < /usr/local/cron/smart-disk-scanner/emailtemplates | |
done | |
fi | |
done | |
} | |
#<!--------- Cron Insertion Function | |
cron_insert_func(){ | |
sh ~/linux-genious-1.1/disk/./cron.sh | |
} | |
#notification_func | |
#main_init | |
#<!----- Argument Passing Menu | |
case $1 in | |
--config) | |
# echo "Config Function " | |
notification_func | |
;; | |
--task) | |
info_grab_func | |
;; | |
--cron) | |
cronchk=$(crontab -l) | |
case $cronchk in | |
*"--task"*) | |
echo "Cron is already added " | |
;; | |
*) | |
cron_insert_func | |
;; | |
esac | |
;; | |
*) | |
echo "Not a Valid Argument" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script is brought up for disk monitoring script can only be use with arguments because this script has multiple functions so i just set this up with arguments
Note : "/usr/local/cron/smart-disk-scanner/emaillist"
Please make sure you have all email ids who needs to have notification email one email id per line.
Regards,
Mansur