some AI generated scripts for inspiration

This commit is contained in:
Jonas Maier 2025-12-03 22:52:49 +01:00
commit cee69984d5
3 changed files with 79 additions and 0 deletions

44
fs.sh Normal file
View File

@ -0,0 +1,44 @@
#!/bin/sh
THRESHOLD=90
echo "Checking disk usage (>= $THRESHOLD%)"
df -P | while IFS= read -r line; do
case "$line" in
Filesystem*|"") continue ;;
esac
fs=$(printf '%s\n' "$line" | awk '{print $1}')
usep=$(printf '%s\n' "$line" | awk '{print $5}' | tr -d '%')
mountp=$(printf '%s\n' "$line" | awk '{print $6}')
# skip empty or loop devices
case "$fs" in
""|/dev/loop*) continue ;;
esac
if [ "$usep" -ge "$THRESHOLD" ] 2>/dev/null; then
printf 'WARNING: %s is %s%% full (mounted on %s)\n' "$fs" "$usep" "$mountp"
fi
done
echo
echo "Checking inode usage (>= $THRESHOLD%)"
df -P -i | while IFS= read -r line; do
case "$line" in
Filesystem*|"") continue ;;
esac
fs=$(printf '%s\n' "$line" | awk '{print $1}')
usep=$(printf '%s\n' "$line" | awk '{print $5}' | tr -d '%')
mountp=$(printf '%s\n' "$line" | awk '{print $6}')
# skip empty or loop devices
case "$fs" in
""|/dev/loop*) continue ;;
esac
if [ "$usep" -ge "$THRESHOLD" ] 2>/dev/null; then
printf 'WARNING: %s has %s%% inode usage (mounted on %s)\n' "$fs" "$usep" "$mountp"
fi
done

27
smart.sh Normal file
View File

@ -0,0 +1,27 @@
#!/bin/sh
if ! command -v smartctl >/dev/null 2>&1; then
echo "Error: smartctl is not installed." >&2
exit 0
fi
# Scan for disks
smartctl --scan | while IFS= read -r line; do
device=$(printf '%s\n' "$line" | awk '{print $1}')
[ -n "$device" ] || continue
echo "Device: $device"
echo "SMART Health Status:"
smartctl -H "$device"
echo
echo "Error Counts:"
# Extract the error log from smartctl -l error
# Works for SATA/SAS/NVMe; if unsupported, smartctl prints a message.
smartctl -l error "$device" 2>/dev/null | \
grep -E "Error Count|read:|write:|uncorrect" || \
echo " No error log or errors not reported."
echo
done

8
zfs.sh Normal file
View File

@ -0,0 +1,8 @@
set -eu
if ! command -v zpool >/dev/null 2>&1; then
echo "zpool command does not exist, assuming no ZFS on this system." >&2
exit 0
fi
zpool status -x