You are not logged in.

#1 2018-03-21 18:50:03

ua4000
Member
Registered: 2015-10-14
Posts: 419

[Solved] How to check: when was the system last updated?

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

#2 2018-03-21 18:53:33

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Re: [Solved] How to check: when was the system last updated?

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 packagesZsh and other configs

Offline

#3 2018-03-21 19:40:02

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [Solved] How to check: when was the system last updated?

awk 'END{sub(/\[/,""); print $1}' /var/log/pacman.log

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#4 2018-03-21 19:43:01

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [Solved] How to check: when was the system last updated?

Or just use checkupdates to see if there any updates available?


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#5 2018-03-21 19:49:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: [Solved] How to check: when was the system last updated?

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

#6 2018-03-22 15:05:07

ua4000
Member
Registered: 2015-10-14
Posts: 419

Re: [Solved] How to check: when was the system last updated?

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 ...

Trilby wrote:

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

#7 2018-03-22 15:20:34

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: [Solved] How to check: when was the system last updated?

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

#8 2018-03-22 15:42:55

progandy
Member
Registered: 2012-05-17
Posts: 5,190

Re: [Solved] How to check: when was the system last updated?

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

#9 2018-03-22 15:56:11

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: [Solved] How to check: when was the system last updated?

progandy wrote:

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

#10 2018-03-22 20:40:31

progandy
Member
Registered: 2012-05-17
Posts: 5,190

Re: [Solved] How to check: when was the system last updated?

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

#11 2018-03-23 03:27:29

NoSuck
Member
Registered: 2015-03-04
Posts: 157
Website

Re: [Solved] How to check: when was the system last updated?

Thanks for mentioning expac.  It looks useful.

Last edited by NoSuck (2018-03-23 03:35:19)

Offline

#12 2018-03-23 14:58:00

ua4000
Member
Registered: 2015-10-14
Posts: 419

Re: [Solved] How to check: when was the system last updated?

$ 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

Board footer

Powered by FluxBB