You are not logged in.
I have more than one arch, and I want the system to remind me to perform an update if the last run of "pacman -Syu" was xx days ago.
Which is the proper way to check this within a shell script ?
Thanks very much!
Last edited by ua4000 (2018-03-23 14:58:53)
Offline
Guess you could make something that audits /var/log/pacman.log but why... just run the command.
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
awk 'END{sub(/\[/,""); print $1}' /var/log/pacman.log
Offline
Offline
day=$((($(date +%s) - $(date -d $(sed -n '/upgrade$/x;${x;s/.\([0-9-]*\).*/\1/p}' /var/log/pacman.log) +%s)) / 86400))
printf 'last update was %d days ago\n' $day
But yeah, just run pacman, it will tell you if there is nothing to do.
This is much better:
#!/bin/sh
awk -F'[][ :-]' '
/upgrade$/ {
last = mktime($2 " " $3 " " $4 " " $5 " " $6 " 00")
}
END {
s = systime() - last;
d = int(s / 86400);
h = int((s - d * 86400) / 3600)
m = int((s - d * 86400 - h * 3600) / 60)
printf "Last update was %d days %d hours and %d minutes ago\nRun pacman now!\n", d, h, m
}
' /var/log/pacman.log
Last edited by Trilby (2018-03-21 20:23:50)
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
Thanks for the help,
yes, looking at /var/log/pacman.log was in my head too - but I wasn't sure if this is the best way. I though also about maybe looking at a timestamp from core.db ...
But yeah, just run pacman, it will tell you if there is nothing to do.
No,No - before doing so, I will get some coffee + cakes and reserve some time, read https://www.archlinux.org/news/ and create a backup/snapshot.
Also I don't want do do this daily, but instead only if needed (e.g. important security fix) or when the system reaches my personal choosen limit, e.g. (e.g. 2 weeks) - so I won't forget one of my archs.
Offline
Find whatever works for you, but updating more frequently makes it much easier.
Certainly there is no harm in updating every couple of weeks. But if you are at your computer daily, it's trivial to run daily (or more) updates. And doing so ensures that if there ever is a snag it is much easier to fix (very few packages would have been updated, so you know exactly what changed and downgrading - if needed - is trivially easy).
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
with expac you can also look for the most recent install date of any package:
date --date="@$(expac --timefmt '%s' "%l" | sort -rn | head -n1)"
Personally, I'd simply set a weekly update schedule, e.g. every saturday. Then you don't have to remember when the last update was and if you ever forget it, you will probably do it on the next weekend.
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |
Offline
with expac you can also look for the most recent install date of any package
But this, like looking just at the last line of pacman's log, does not tell you when the system was last updated. Once can continue installing packages for quite a while without a full system update.
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
It is useful if you are missing the pacman log or it is corrupted, but of course the date is only an approximation. You can narrow it down a bit more by using the last package build date (%b) in the sync database, but that breaks if you do the unsupported sync without upgrade.
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |
Offline
Thanks for mentioning expac. It looks useful.
Last edited by NoSuck (2018-03-23 03:35:19)
Offline
$ egrep 'pacman -Syu' /var/log/pacman.log | tail -1
[2018-03-23 15:30] [PACMAN] Running 'pacman -Syu --noconfirm --noprogressbar --verbose'
And with the code from Trilby some date calculation is possibe.
Thanks to all!
Offline