Martin T <m4rtn...@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