Skip to content

Instantly share code, notes, and snippets.

@marshki
Last active July 5, 2023 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshki/9e6ded589b0b5f42fcc9a136a4d0403c to your computer and use it in GitHub Desktop.
Save marshki/9e6ded589b0b5f42fcc9a136a4d0403c to your computer and use it in GitHub Desktop.
Nuke inodes on: /dev/md0 partition (Synology) if capacity >= 90%.
#!/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