Date: Wed, 27 Jan 2021 10:05:57 +0100 From: Michael Gmelin <freebsd@grem.de> To: Peter Pentchev <roam@ringlet.net> Cc: Yasuhiro Kimura <yasu@utahime.org>, freebsd-ports@freebsd.org Subject: Re: List of packages upgraded last time `pkg upgrade` was executed Message-ID: <20210127100557.4cae09a8@bsd64.grem.de> In-Reply-To: <YBEl2jz%2B3om7wEIz@straylight.m.ringlet.net> References: <20210127.101755.2072625504289992511.yasu@utahime.org> <CAOjFWZ5ZUjZeoUbj_Pw1ERdeDsexTAORvvpAG4GMcLSmMGU0%2Bw@mail.gmail.com> <20210127.105722.43271801537229412.yasu@utahime.org> <YBEl2jz%2B3om7wEIz@straylight.m.ringlet.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 27 Jan 2021 10:35:38 +0200 Peter Pentchev <roam@ringlet.net> wrote: > On Wed, Jan 27, 2021 at 10:57:22AM +0900, Yasuhiro Kimura wrote: > > From: Freddie Cash <fjwcash@gmail.com> > > Subject: Re: List of packages upgraded last time `pkg upgrade` was > > executed Date: Tue, 26 Jan 2021 17:26:29 -0800 > > > > > /var/log/messages and I think /var/log/daemon include the output > > > of the pkg commands. If you have the log files backed up from the > > > last time it was run, you could grep for pkg in those. > > > > > > No idea if this info is also stored in the sqlite databases pkg > > > uses. > > > > Thank you for reply. But my intention is to write shell script that > > gets the list of upgraded packages and does something by using > > it. Because of that the list need to be gotton without any user > > interaction. So unfortunately your method is not applicable to my > > case. > > Well, there is the option of running a pkg query before and after > the upgrade and comparing the results... especially if you write it in > a higher-level language than the shell, it Should Not Be Too Hard(tm) > to figure out which packages have changed their version, what new > ones have appeared, which ones have been removed... > > But, yeah, it is certainly easy for me to suggest that somebody else > write something "simple" :) > This will give you a list of all packages that were updated/installed last: pkg query -e %t=$(pkg query %t | sort -n | tail -n1) %n-%v Explained: $(pkg query %t | sort -n | tail -n1) - Get timestamps of when packages were installed - Sort numerically - Take the last one (which is the latest) Feed this into `pkg query %t=x %n-%v` which returns all packages matching that latest timestamp (== when last set of packages were installed) and outputs their name and version. As far as I can tell, packages installed by the same pkg invocation run share the same installation timestamp (I didn't check the pkg sources, but that's what appears to be the case), that's why this works. This resulting list won't include the pkg package itself in case it was updated as part as the run. There might also be other multi-pass scenarios of pkg I'm not aware of though. In case you know when pkg upgrade was called last, you can simply feed it the timestamp directly, like in: pkg query -e "%t>=1609545326" %n-%v If you use a script to do upgrades, you could store the timestamp as part of that and do something like this: touch /tmp/lastupgrade pkg upgrade # then, later: pkg query -e "%t>=$(stat -f %m /tmp/lastupgrade)" %n-%v Cheers, Michael -- Michael Gmelin
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20210127100557.4cae09a8>