Re: Detect upgradable packages in shell script ran as a non-root user
- To: debian-user@lists.debian.org
- Subject: Re: Detect upgradable packages in shell script ran as a non-root user
- From: kushal@locationd.net
- Date: Thu, 01 Dec 2016 10:47:50 +0530
- Message-id: <[🔎] 87zikgdy81.fsf@locationd.net>
- In-reply-to: <CAJx5YvG2VpJo+GozG+gm4HA1K5S+DOPK2obKDnFb-cm2pQvpww@mail.gmail.com> (Martin T.'s message of "Wed, 30 Nov 2016 17:09:20 +0200")
- References: <CAJx5YvG2VpJo+GozG+gm4HA1K5S+DOPK2obKDnFb-cm2pQvpww@mail.gmail.com>
Martin T <m4rtntns@gmail.com> writes:
> Hi,
>
> I would like to run a cron job which periodically checks if I have
> upgradable packages. One way to do it is probably like this:
>
> $ apt-get upgrade -s | grep -q "^0 upgraded"
>
> In case exit code is >0, then there are upgradable packages. The
> second solution I came up with is:
>
> $ for package in $(dpkg-query -f '${binary:Package}\n' -W); do\
> apt-show-versions -u "$package" &>/dev/null && break;\
> done
>
> Again, if exit code is >0, then there is at least one upgradable
> package. Of course, a solution like "apt-show-versions | grep -q
> "upgradeable"" would also work.
>
> For me the "apt-get upgrade -s | grep -q "^0 upgraded"" seems to be
> the most reasonable solution, but maybe there is even a better way?
>
Does "apt list --upgradable" suit your needs?
Its output format is not stable and it produces a WARNING on stderr if
you use it in a pipe, which might disqualify it for cron usage, but I
use it when I'm check things by hand.
--
regards,
kushal
Reply to: