Add Updates section to health-check.sh
This commit is contained in:
1 parent
4b27599927
commit
4eec7a0c6e
1 file changed
+55
@@ -228,6 +228,59 @@ check_hub() {
|
||||
echo ""
|
||||
}
|
||||
|
||||
check_updates() {
|
||||
header "Updates"
|
||||
|
||||
local now last_raw last_epoch last_days boot_raw boot_epoch boot_days
|
||||
now=$(date +%s)
|
||||
|
||||
last_raw=$(grep -h '^Start-Date' /var/log/apt/history.log 2>/dev/null | tail -1 | cut -d' ' -f2- || true)
|
||||
if [ -z "$last_raw" ]; then
|
||||
last_raw=$(zgrep -h '^Start-Date' /var/log/apt/history.log.*.gz 2>/dev/null | sort | tail -1 | cut -d' ' -f2- || true)
|
||||
fi
|
||||
|
||||
if [ -n "$last_raw" ]; then
|
||||
last_raw=$(echo "$last_raw" | tr -s ' ')
|
||||
last_epoch=$(date -d "$last_raw" +%s 2>/dev/null || echo "")
|
||||
else
|
||||
last_epoch=""
|
||||
fi
|
||||
|
||||
if [ -n "$last_epoch" ]; then
|
||||
last_days=$(( (now - last_epoch) / 86400 ))
|
||||
if [ "$last_days" -ge 30 ]; then
|
||||
warn "Last updated $(date -d "@$last_epoch" '+%b %d, %Y %I:%M %p') (${last_days} days ago)"
|
||||
else
|
||||
ok "Last updated $(date -d "@$last_epoch" '+%b %d, %Y %I:%M %p') (${last_days} days ago)"
|
||||
fi
|
||||
else
|
||||
warn "Could not determine last update time"
|
||||
fi
|
||||
|
||||
boot_raw=$(uptime -s 2>/dev/null || true)
|
||||
if [ -n "$boot_raw" ]; then
|
||||
boot_epoch=$(date -d "$boot_raw" +%s 2>/dev/null || echo "")
|
||||
else
|
||||
boot_epoch=""
|
||||
fi
|
||||
|
||||
if [ -n "$boot_epoch" ]; then
|
||||
boot_days=$(( (now - boot_epoch) / 86400 ))
|
||||
ok "Last rebooted $(date -d "@$boot_epoch" '+%b %d, %Y %I:%M %p') (${boot_days} days ago)"
|
||||
else
|
||||
warn "Could not determine last reboot time"
|
||||
fi
|
||||
|
||||
if [ -f /var/run/reboot-required ]; then
|
||||
warn "Reboot required"
|
||||
if [ -f /var/run/reboot-required.pkgs ]; then
|
||||
sort -u /var/run/reboot-required.pkgs | sed 's/^/ /'
|
||||
fi
|
||||
else
|
||||
ok "No reboot required"
|
||||
fi
|
||||
}
|
||||
|
||||
check_common
|
||||
check_disk
|
||||
|
||||
@@ -239,4 +292,6 @@ if [ "$IS_HUB" = true ]; then
|
||||
check_hub
|
||||
fi
|
||||
|
||||
check_updates
|
||||
|
||||
echo ""
|
||||
Reference in new issue
Block a user