On 29/10/21 2:53 pm, Peter wrote:
On 28/10/21 9:39 pm, richard lucassen wrote:
Hello list,

Anyone here who wrote a shell script that deletes messages older than X
days from the hold queue?

It's just a one-liner with postqueue -j and a bit of perl:

postqueue -j | perl -MJSON -MData::Dumper -ne 'my $j = decode_json($_); next unless $j->{queue_name} eq "hold" && (time()-$j->{arrival_time}) > 86400; system qw(postsuper -d),$j->{queue_id};'

86400 is the number of seconds in a day, adjust accordingly.

Or even better:

postqueue -j | perl -MJSON -MData::Dumper -ne 'my $j = decode_json($_); next unless $j->{queue_name} eq "hold" && (time()-$j->{arrival_time}) > 86400; print $j->{queue_id},"\n"' | postsuper -d -

...and Viktor gave an example with jq instead of perl, take your pick of which tool you'd rather use, but I would avoid grep and sed. What's the point of even using JSON output if you're going to turn around and hack at it with grep and sed?

Peter

Reply via email to