Skip to content

Commit

Permalink
Pushing scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ojd2 committed Jan 21, 2017
1 parent 33358d7 commit 7c9d6e8
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
55 changes: 55 additions & 0 deletions block-usg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

# vars #
disk="/dev/mapper/fedora-root" # disk to monitor
current_blocks=$(df -m | grep ${disk} | awk {'print $2'}) # get amount of blocks used
mounted=$(df -m | grep ${disk} | awk {'print $6'}) # get disk information
max_threshold="20000" # max 20000 amount of blocks

email="[email protected]" # mail to sent alert to

# functions #
function max_blocks_exceeded() {

# tell that mail is being sent
echo "Max amount of MB blocks (${max_threshold}) has exceeded as your MB block amount is set at ${max_threshold} mounted on ${mounted}."
echo "Sending Alert..."

# check if the mail program exist
type email > /dev/null 2>&1 || {
echo >&2 "Mail does not exist. Install it and run script again. Aborting script..."; exit;
}

# if the mail program exist we continue to this and send the alert
mailbody="Max amount of MB blocks (${max_threshold}) exceeded. Current disk (${disk}) usage is at ${current_blocks} mounted on ${mounted}."
echo ${mailbody} | mail -s "MB Blocks alert!" "${email}"

echo "Mail was sent to ${email}"
}

function abort() {

echo "No problems. Disk (${disk}) mounted on ${mounted} current MB block limit is at ${current_blocks}. Threshold is set to ${max_threshold}."
}

function main() {

# check if a valid disk is chosen
if [ ${current_blocks} ]; then
# check if current MB block disk usage is greater than or equal to max usage.
if [ ${current_blocks%?} -ge ${max_threshold%?} ]; then
# if it is greater than or equal to max usage we call our max_exceeded function and send mail
max_blocks_exceeded
else
# if it is ok we do nothing
abort
fi
else
# if the disk is not valid, print valid disks on system
echo "Set a valid MB block env, and run script again. Your environment looks like the following: "
df -m
fi
}

# init #
main
55 changes: 55 additions & 0 deletions disk-usg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

# vars #
disk="/dev/mapper/fedora-root" # disk to monitor
current_capacity=$(df -P | grep ${disk} | awk {'print $5'}) # get disk usage from monitored POSIX disk
mounted=$(df -P | grep ${disk} | awk {'print $6'}) # get disk information via POSIX
max_capacity="90%" # max 90% mount capacity

email="[email protected]" # email to

# functions #
function max_exceeded() {

# tell that mail is being sent
echo "Max capacity of (${max_capacity}) has exceeded as your disk usage is it at ${current_capacity} mounted on ${mounted}."
echo "Sending Alert..."

# check if the mail program exist
type email > /dev/null 2>&1 || {
echo >&2 "Mail does not exist. Install it and run script again. Aborting script..."; exit;
}

# if the mail program exist we continue to this and send the alert
mailbody="Max capacity (${max_usage}) exceeded. Current disk (${disk}) usage is at ${current_capacity} mounted on ${mounted}."
echo ${mailbody} | mail -s "Disk alert!" "${email}"

echo "Mail was sent to ${email}"
}

function abort() {

echo "No problems. Disk (${disk}) mounted on ${mounted} capacity is at ${current_capacity}. Max is set to ${max_capacity}."
}

function main() {

# check if a valid disk is chosen
if [ ${current_capacity} ]; then
# check if current disk usage is greater than or equal to max usage.
if [ ${current_capacity%?} -ge ${max_capacity%?} ]; then
# if it is greater than or equal to max usage we call our max_exceeded function and send mail
max_exceeded
else
# if it is ok we do nothing
abort
fi
else
# if the disk is not valid, print valid disks on system
echo "Set a valid POSIX disk env, and run script again. Your environment looks like the following: "
df -P
fi
}

# init #
main

0 comments on commit 7c9d6e8

Please sign in to comment.