Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #175280 > unrolled thread
| Started by | Martin T <m4rtntns@gmail.com> |
|---|---|
| First post | 2016-11-30 16:10 +0100 |
| Last post | 2016-12-02 12:50 +0100 |
| Articles | 9 — 9 participants |
Back to article view | Back to linux.debian.user
Detect upgradable packages in shell script ran as a non-root user Martin T <m4rtntns@gmail.com> - 2016-11-30 16:10 +0100
Re: Detect upgradable packages in shell script ran as a non-root user Greg Wooledge <wooledg@eeg.ccf.org> - 2016-11-30 16:20 +0100
Re: Detect upgradable packages in shell script ran as a non-root user Shin Ice <shin.ice@shinice.net> - 2016-11-30 16:40 +0100
Re: Detect upgradable packages in shell script ran as a non-root user Liam O'Toole <liam.p.otoole@gmail.com> - 2016-11-30 18:50 +0100
Re: Detect upgradable packages in shell script ran as a non-root user Joe <joe@jretrading.com> - 2016-11-30 19:40 +0100
Re: Detect upgradable packages in shell script ran as a non-root user kushal@locationd.net - 2016-12-01 06:20 +0100
Re: Detect upgradable packages in shell script ran as a non-root user Tixy <tixy@yxit.co.uk> - 2016-12-02 09:00 +0100
RE: Detect upgradable packages in shell script ran as a non-root user Bonno Bloksma <b.bloksma@tio.nl> - 2016-12-02 12:40 +0100
Re: Detect upgradable packages in shell script ran as a non-root user Jonathan Dowland <jmtd@debian.org> - 2016-12-02 12:50 +0100
| From | Martin T <m4rtntns@gmail.com> |
|---|---|
| Date | 2016-11-30 16:10 +0100 |
| Subject | Detect upgradable packages in shell script ran as a non-root user |
| Message-ID | <sJeGd-7Ih-25@gated-at.bofh.it> |
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?
thanks,
Martin
[toc] | [next] | [standalone]
| From | Greg Wooledge <wooledg@eeg.ccf.org> |
|---|---|
| Date | 2016-11-30 16:20 +0100 |
| Message-ID | <sJePU-7Lw-33@gated-at.bofh.it> |
| In reply to | #175280 |
On Wed, Nov 30, 2016 at 05:09:20PM +0200, Martin T wrote: > 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" But you have to run apt-get update first, AS root. (Your subject line includes the phrase "as a non-root user", but you neglected to include this important piece of information in the body of the email. I say this now, because someone might change the subject header later.) A script that only tells you whether you neglected to do an upgrade after your last update isn't all that useful, at least to me. I very rarely forget to follow up the update with an upgrade.
[toc] | [prev] | [next] | [standalone]
| From | Shin Ice <shin.ice@shinice.net> |
|---|---|
| Date | 2016-11-30 16:40 +0100 |
| Message-ID | <sJf9f-7RM-5@gated-at.bofh.it> |
| In reply to | #175281 |
[Multipart message — attachments visible in raw view] — view raw
On Wed, Nov 30, 2016 at 10:13:40AM -0500, Greg Wooledge wrote: > On Wed, Nov 30, 2016 at 05:09:20PM +0200, Martin T wrote: > > 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" > > But you have to run apt-get update first, AS root. (Your subject line > includes the phrase "as a non-root user", but you neglected to include > this important piece of information in the body of the email. I say > this now, because someone might change the subject header later.) > root is needed for the update, maybe what you search is cron-apt ;) https://debian-administration.org/article/162/A_short_introduction_to_cron-apt -- I'm just a placeholder for a really awesome signature... ...that is still missing *sob*
[toc] | [prev] | [next] | [standalone]
| From | Liam O'Toole <liam.p.otoole@gmail.com> |
|---|---|
| Date | 2016-11-30 18:50 +0100 |
| Message-ID | <sJhb3-F2-3@gated-at.bofh.it> |
| In reply to | #175280 |
On 2016-11-30, Martin T <m4rtntns@gmail.com> wrote:
> 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.
'apt-show-versions -u | wc -l' is another option.
>
> 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?
>
>
> thanks,
> Martin
>
>
--
Liam
[toc] | [prev] | [next] | [standalone]
| From | Joe <joe@jretrading.com> |
|---|---|
| Date | 2016-11-30 19:40 +0100 |
| Subject | Re: Detect upgradable packages in shell script ran as a non-root user |
| Message-ID | <sJhXs-1dw-15@gated-at.bofh.it> |
| In reply to | #175280 |
On Wed, 30 Nov 2016 17:09:20 +0200 Martin T <m4rtntns@gmail.com> wrote: > > 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? > > I've found upgrade-system to be useful, and when installed, it sends a daily email showing its proposals. -- Joe
[toc] | [prev] | [next] | [standalone]
| From | kushal@locationd.net |
|---|---|
| Date | 2016-12-01 06:20 +0100 |
| Message-ID | <sJrWN-7OY-3@gated-at.bofh.it> |
| In reply to | #175280 |
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
[toc] | [prev] | [next] | [standalone]
| From | Tixy <tixy@yxit.co.uk> |
|---|---|
| Date | 2016-12-02 09:00 +0100 |
| Subject | Re: Detect upgradable packages in shell script ran as a non-root user |
| Message-ID | <sJQVh-HL-25@gated-at.bofh.it> |
| In reply to | #175280 |
On Wed, 2016-11-30 at 17:09 +0200, Martin T wrote: > 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: What do you want to do with the information once you got it? I ask because Debian includes some packages to do various periodic things for updates and you might be reinventing the wheel. E.g. I use apticron [1] on all the machines I manage which periodically checks if there's upgradable packages an emails me a summary of them if there are. I believe there are also means on doing other things. [1] https://debian-administration.org/article/491/Automatic_package_update_nagging_with_apticron -- Tixy
[toc] | [prev] | [next] | [standalone]
| From | Bonno Bloksma <b.bloksma@tio.nl> |
|---|---|
| Date | 2016-12-02 12:40 +0100 |
| Subject | RE: Detect upgradable packages in shell script ran as a non-root user |
| Message-ID | <sJUm5-3er-15@gated-at.bofh.it> |
| In reply to | #175322 |
Hi, What I have been using for years is a little script to send me (and the servicedesk) a daily mail: #!/bin/bash # MAILREC is space separated MAILREC="myemail@tio.nl helpdesk@tio.nl" SUBJECT="Upgrade report voor $HOSTNAME" TMPFILE=/tmp/upgradereport.tmp # Step 1: update repositories... apt-get update >/dev/null 2>&1 # Step 2: show upgrades apt-get --dry-run upgrade | grep Inst > $TMPFILE if egrep -q ^Inst $TMPFILE then mail -s "$SUBJECT" $MAILREC < $TMPFILE fi rm $TMPFILE This script simply gets called from crontab: # Test once a day if there are any upgrades to be apllied 5 5 * * 0 root /usr/local/bin/upgradereport.sh It does run as root but then why shouldn't it? Add the -V switch to the apt-get upgrade line to see from which version to which version the upgrade is needed. I just do not need that in my mail, I'll see that when I perform the upgrade. Bonno Bloksma
[toc] | [prev] | [next] | [standalone]
| From | Jonathan Dowland <jmtd@debian.org> |
|---|---|
| Date | 2016-12-02 12:50 +0100 |
| Message-ID | <sJUvL-3hJ-7@gated-at.bofh.it> |
| In reply to | #175280 |
[Multipart message — attachments visible in raw view] — view raw
One of the problems you will have with many (any?) of the solutions proposed is they rely on the current state of your local apt package metadata cache. Which is to say, if that is not up-to-date, then you are only going to get stale information; and you need to be root to update it. I would suggest installing and enabling unattended-upgrades iiwy. -- Jonathan Dowland Please do not CC me, I am subscribed to the list.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.debian.user
csiph-web