Last active
July 5, 2023 19:54
-
-
Save marshki/9e6ded589b0b5f42fcc9a136a4d0403c to your computer and use it in GitHub Desktop.
Nuke inodes on: /dev/md0 partition (Synology) if capacity >= 90%.
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
#!/usr/bin/env bash | |
# | |
# inode_eraser | |
# | |
# Nuke inodes on: /dev/md0 partition (Synology) if capacity >= 90%. | |
# Place file in: /usr/local/bin. | |
# Set permisisons: chmod 644. | |
# Set cronjob by editing: /etc/crontab, & restart service: systemctl restart crond | |
# | |
# Author: M. Krinitz <mjk235 [at] nyu [dot] edu> | |
# Date: 02-Jul-2023 | |
# License: MIT | |
timestamp=$(date "+%b %d %X") | |
inode_percentage=$(df -i | awk 'NR==2 {sub(/%/, "", $5); print $5}') | |
threshold=90 | |
inode_scrub_command="/var/packages/SecureSignIn/target/tool/updater -v 240" | |
end='exit 1' | |
root_check() { | |
if [ "$EUID" -ne "0" ] ; then | |
printf "%s\n" "ERROR: Root privileges are required to continue. Exiting." | |
$end | |
fi | |
} | |
inode_comparison_check() { | |
if [ "$inode_percentage" -ge $threshold ]; then | |
printf "%s\n" "Inode usage: HIGH ($inode_percentage%). Continuing..." | |
else | |
printf "%s\n" "Inode usage: LOW ($inode_percentage%). Exiting." | |
$end | |
fi | |
} | |
inode_scrub() { | |
printf "%s\n" "Running inode scrub command. Please hold..." | |
if ! output=$($inode_scrub_command 2>&1); then | |
printf "%s\n" "Error: Inode scrub command failed. Details.: $output" | |
$end | |
fi | |
} | |
exit_status() { | |
print $retVal | |
if [[ $retVal -ne 0 ]]; then | |
printf "%s\n" "ACHTUNG!!! Something went wrong, homie." | |
else | |
printf "%s\n" "Done. Exiting @ $timestamp." | |
fi | |
} | |
main() { | |
root_check | |
inode_comparison_check | |
inode_scrub | |
} | |
main "$@" | |
retVal=$? | |
exit_status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment