Last active
October 6, 2023 06:43
-
-
Save yangl1996/44349cd3317be844e7dcfc60c0a05863 to your computer and use it in GitHub Desktop.
Check pacman last upgrade time
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
# won't handle situations where /var/log/pacman.log doesn't exist or full system upgrade not run once | |
last_upgrade_time=$(grep "\[PACMAN\] starting full system upgrade" /var/log/pacman.log | tail -1 | grep -oP '\[\K[^\]]+' | head -1) | |
last_upgrade_utime=$(date '+%s' -d "$last_upgrade_time") | |
current_utime=$(date '+%s') | |
time_diff=$(( $current_utime - $last_upgrade_utime )) | |
day_diff=$(( $time_diff / 86400 )) | |
hour_diff=$(( ($time_diff - 86400 * $day_diff) / 3600 )) | |
# colors | |
RED='\033[31m' | |
NC='\033[0m' | |
if (( $day_diff > 6 )); then | |
echo -e "${RED}You have not upgraded your system for ${day_diff} days ${hour_diff} hours!${NC}" | |
echo "Check Arch news page and Run \"pacman -Syu\" to upgrade." | |
else | |
echo "System last upgraded at ${last_upgrade_time} (${day_diff} days ${hour_diff} hours ago)." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment