Re: Detect upgradable packages in shell script ran as a non-root user

2016-12-02 Thread Jonathan Dowland
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.


signature.asc
Description: Digital signature


RE: Detect upgradable packages in shell script ran as a non-root user

2016-12-02 Thread Bonno Bloksma
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="myem...@tio.nl helpd...@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
 


Re: Detect upgradable packages in shell script ran as a non-root user

2016-12-01 Thread Tixy
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  



Re: Detect upgradable packages in shell script ran as a non-root user

2016-11-30 Thread kushal
Martin T  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



Re: Detect upgradable packages in shell script ran as a non-root user

2016-11-30 Thread Joe
On Wed, 30 Nov 2016 17:09:20 +0200
Martin T  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



Re: Detect upgradable packages in shell script ran as a non-root user

2016-11-30 Thread Liam O'Toole
On 2016-11-30, Martin T  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



Re: Detect upgradable packages in shell script ran as a non-root user

2016-11-30 Thread Shin Ice
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*


signature.asc
Description: PGP signature


Re: Detect upgradable packages in shell script ran as a non-root user

2016-11-30 Thread Greg Wooledge
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.