Last active
July 8, 2018 11:11
-
-
Save photonxp/cc37690cf61c642d68fe3a388c324edc to your computer and use it in GitHub Desktop.
script to check if the boot partition has enough remaining space
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 | |
# call this file in your profile as background job | |
set -e | |
# Adjust this value if it's too long or too short to wait | |
sleep 600 | |
# You need to change this path for your own directory | |
BASE_DIR=/path/to/your_notify_dir | |
cd $BASE_DIR | |
SCRIPT=./notify_when_boot_full.sh | |
LOG_FILE=./notify_boot_in_profile.log | |
touch $LOG_FILE | |
$SCRIPT 2>&1 >>$LOG_FILE & | |
exit 0 |
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 | |
# The scripts may or may not work, depending on your environment. | |
# The boot partition should be mounted as /boot (Run df -h to check), otherwise | |
# you should change the part `grep /boot$` in the script yourself. | |
# You need to move the script files to the /path/to/your_notify_dir, with proper permissions: | |
# notify_when_boot_full.sh | |
# notify_boot_in_profile.sh (See the other script below this one) | |
# INSTRUCTIONS ON LOGIN USAGE with .profile | |
# gedit ~/.profile | |
# add the following line at the bottom of the profile file: | |
# /path/to/your_notify_dir/notify_boot_in_profile.sh & | |
# (the & above is required, and also change the path to your script) | |
# The script will wait 10 minutes after you login by default | |
# If the script couldn't work in ~/.profile as background job &, check permissions and the log. | |
# You can also try cron job. | |
# Just change the file name notify_boot_in_profile.sh to notify_boot_in_cron.sh, as well as its content accordingly. | |
set -e | |
# sleep 600 | |
# Change the THRESHOLD to the minimal boot space you alert | |
THRESHOLD=400 | |
TARGET_USER=$USER | |
# Uncomment the next line if you try to use cron jobs. Use your login name to replace your_login_user_name | |
#TARGET_USER=your_login_user_name | |
# YearMonthDay.HourMinute | |
datef=`date '+%Y%m%d.%H%M'` | |
echo | |
echo $datef $0 | |
# Get available boot memory in mega bytes, e.g., 100M | |
avail_m=$(df -h | grep [[:blank:]]/boot$ | awk '{ print $4 }') | |
echo $avail_m | |
# Change available boot memory to pure number without units, e.g., 100 | |
avail_basic=${avail_m::-1} | |
# Notify the $TARGET_USER if available memory is below the $THRESHOLD | |
if [ $avail_basic -le $THRESHOLD ] | |
then | |
# adjust the environment value | |
eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $TARGET_USER gnome-session)/environ)" | |
#export DISPLAY=:0 | |
/usr/bin/notify-send "Boot disk is low: $avail_m" | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment