"linux-purge" does not support "grep -q ..." on its ouput in simulation mode.

Bug #1883765 reported by Seb Bonnard
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
linux-purge
Fix Released
Undecided
Jarno Suni

Bug Description

Hi,

I've defined the folling alias to cleanup old kernels :

alias cleanupOldKernels="\linux-purge -k 2 -s | grep -q ', [^0] to remove' && sudo screen -L \linux-purge -k 2"

This alias uses the grep command to check for older kernels than removes them if necessary.

The grep command by itself is supported :
$ linux-purge -k 2 -s | grep ', [^0] to remove'
0 upgraded, 0 newly installed, 3 to remove and 1 not upgraded.
But when I use `grep -q`, `linux-purge` complains :
$ linux-purge -k 2 -s | grep -q ', [^0] to remove'
[linux-purge] ERROR: Aborting due to an unknown error (141).

Can you please fix this and increment the version number upto something like v1.0.1 ?

Seb Bonnard (sebma)
description: updated
Jarno Suni (jarnos)
Changed in linux-purge:
assignee: nobody → Jarno Suni (jarnos)
status: New → In Progress
Revision history for this message
Jarno Suni (jarnos) wrote :

What do you use the version number for? I have been thinking about implementing the versioning, but linux-purge has not been released as a package, yet, and maybe never will. Still, it would be good to know which commit of linux-purge is used, so knowing the git hash id would be good. That is not a version number in sense you could tell of two ids which is newer, though, without referring to git. Maybe counting the commits would do for minor version number, so the next one would be 1.103 or 1.0.103, or I could add separate reporting of the used git commit.

Revision history for this message
Jarno Suni (jarnos) wrote :

As for the error message issue, one option to avoid it is simply to add 2>/dev/null in the end of the linux-purge command in your alias or command line. I could suppress the error message for broken pipe error in linux-purge script, and let the script have exit status 141, but the message might be useful in debugging sometimes. Still, most tools do not give an error message in such a case, so I'll consider changing this.

Anyway, as for checking whether linux-purge would purge something, grepping its output is not be the ideal solution. (And it is tricky: your regular expression would not work, if there were "10 to remove".) I could add a separate option giving e.g. the list of the packages, instead.

Revision history for this message
Seb Bonnard (sebma) wrote :

@jarnos Hi, I proposed a version number because I want to be sure I have the latest release of script.
But you could as well use a build number as well.

Thanks for the regexp notice, I'll use `grep ', [1-9][0-9]* to remove'` untill you implement that option to list the packages that would be removed.

Thanks and congratulation for this great tool !

Revision history for this message
Seb Bonnard (sebma) wrote :

@jarnos Redirecting errors to /dev/null is bad idea. Some error could inform the user of a serious pb. (filesystem errors for example).

BTW : I changed my regexp to this : `grep -wq '^Purg'`

Jarno Suni (jarnos)
Changed in linux-purge:
status: In Progress → Fix Committed
Revision history for this message
Jarno Suni (jarnos) wrote :

With the latest version it is better to check, if the output of

linux-purge --list --keep=2

is non-empty to check if linux-purge would purge something by "sudo linux-purge --keep=2".

Revision history for this message
Seb Bonnard (sebma) wrote :

@jarnos
Your new version (1.0.119-c64222c) works fine on Ubuntu Xenial but it has a strange behavior on Ubuntu Bionic :
$ linux-version list
4.15.0-118-generic
4.4.0-190-generic
$ linux-purge --list --keep=2
linux-image-4.4.0-187-generic
linux-image-4.4.0-189-generic
linux-modules-4.4.0-187-generic
linux-modules-4.4.0-189-generic
linux-modules-extra-4.4.0-187-generic

Maybe it's because of my Xenial to Bionic upgrade.

Revision history for this message
Jarno Suni (jarnos) wrote :

Please attach the file generated by

linux-purge --list --keep=2 --debug

Besides, do one of the following scripts output something?

for i in /var/log/dpkg.log.*.gz; do gzip -cd $i | grep --label=$i -FH 'purge linux-generic'; done

grep -FH 'purge linux-generic' /var/log/dpkg.log /var/log/dpkg.log.?

Revision history for this message
Jarno Suni (jarnos) wrote :

At least you should ensure that you have linux-generic package installed.

Revision history for this message
Jarno Suni (jarnos) wrote :

See also the latest Announcements in the Overview page.

Jarno Suni (jarnos)
Changed in linux-purge:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.