u/Electrical-Lab-9593

Looking for a cheap mini pc to run jellyfin

i have seen that the intel n series like 100/150 are good, all it needs it run jellyfin on Linux, and probably put an external usb3 hard drive for the media

any recommendations for UK

reddit.com
u/Electrical-Lab-9593 — 4 days ago
▲ 6 r/bash

Bash script to cull syslog.x files when disk is low

this is for scenario i have where server are used a log fowarders, its the sole job of the server spool logs that get pushed upstream, does the logic look ok, any gotchas you can see, i made a check for locks on syslog.1 as i don't know if logrotate or syslog could be doing something with the file.

#!/bin/bash

# cleanup_syslog.sh

# Checks free disk space on the partition holding /var/log.

# If free space is below 10% OR below 3 GB, deletes the oldest

# syslog archive file in /var/log.

LOG_DIR="/var/log"

THRESHOLD_PERCENT=10

THRESHOLD_BYTES=$((3 * 1024 * 1024 * 1024)) # 3 GB in bytes

# ----------------------------------------------------------

# Get filesystem stats for the partition that holds /var/log

# ---------------------------------------------------------

# df output (POSIX): Filesystem 1K-blocks

read -r fs total_kb used_kb avail_kb use_pct mount \

< <(df -P "$LOG_DIR" | tail -1)

avail_bytes=$(( avail_kb * 1024 ))

total_bytes=$(( total_kb * 1024 ))

# Calculate free percentage

if [[ "$total_bytes" -eq 0 ]]; then

echo "ERROR: Could not determine total disk size for $LOG_DIR" >&2

exit 1

fi

free_pct=$(( avail_bytes * 100 / total_bytes ))

echo "Partition : $fs (mounted at $mount)"

echo "Total : $(( total_bytes / 1024 / 1024 / 1024 )) GB"

echo "Free : $(( avail_bytes / 1024 / 1024 / 1024 )) GB ($free_pct%)"

echo "Thresholds: < ${THRESHOLD_PERCENT}% OR < $(( THRESHOLD_BYTES / 1024 / 1024 / 1024 )) GB"

echo ""

# Check whether cleanup is needed

needs_cleanup=0

if [[ "$free_pct" -lt "$THRESHOLD_PERCENT" ]]; then

echo "WARNING: Free space is ${free_pct}% which is below the ${THRESHOLD_PERCENT}% threshold."

needs_cleanup=1

fi

if [[ "$avail_bytes" -lt "$THRESHOLD_BYTES" ]]; then

echo "WARNING: Free space is $(( avail_bytes / 1024 / 1024 )) MB which is below the 3 GB threshold."

needs_cleanup=1

fi

if [[ "$needs_cleanup" -eq 0 ]]; then

echo "Disk space is OK. No cleanup needed."

exit 0

fi

# --------------------------------------------------------------------------

# Find the oldest syslog archive and delete it

# Syslog archives match: syslog.*.gz or syslog.* (rotated by logrotate)

# Use ls -t (newest first) and take the last entry = oldest file.

# -1 ensures one file per line; grep narrows to syslog archives only.

oldest_archive=$(

ls -1t "$LOG_DIR"/syslog.* 2>/dev/null \

| grep -E 'syslog\.[0-9]' \

| tail -1

)

if [[ -z "$oldest_archive" ]]; then

echo "No syslog archive files found in $LOG_DIR to delete."

exit 0

fi

if fuser "$oldest_archive" > /dev/null 2>&1; then

echo "File is in use, skipping"

else

echo "Deleting oldest syslog archive: $oldest_archive"

rm -f "$oldest_archive"

fi

if [[ $? -eq 0 ]]; then

echo "Successfully deleted: $oldest_archive"

else

echo "ERROR: Failed to delete $oldest_archive" >&2

exit 1

fi

exit 0

reddit.com
u/Electrical-Lab-9593 — 4 days ago