[linux] Re: cli sqlite lezer?

Eric de Hont eric op hobiho.nl
Vr Sep 19 21:30:22 CEST 2014


Op 19-09-14 om 18:49 schreef hans paijmans:
> On 19-09-14 17:52, Eric de Hont wrote:
>> Op 19-09-14 om 15:32 schreef hans paijmans:
>>> On 19-09-14 13:03, Johan van Dijk wrote:
>>>> SELECT sum(visit_count) FROM moz_places WHERE url LIKE "%wikipedia.org%";
>>> Ja, maar nu via een shellscript...
[knip]
>> Gescript met bash:
>>
>> #!/bin/bash
>>
>> ########################################
[knip]
> Hartstikke bedankt... 

Ik had al een paar weken niet geperld, dus als vingeroefening:

#!/usr/bin/perl

use strict;

use warnings;

use File::Find;

my $databasedir = "$ENV{HOME}/.mozilla/firefox/";

my $database    = most_recent($databasedir, 'places.sqlite');

my $query = q{'SELECT sum(visit_count) FROM moz_places WHERE url LIKE "%wikipedia.org/%";'};

chomp(my $count = qx{sqlite3 $database $query})

     or die "Fout! Fout in aanroep sqlite\n";

print "Wikipedia is ", $count?"$count maal ":"(nog) niet ", "bezocht.\n";

sub most_recent {

# usage:    most_recent(<origin>,<file_name>)

# Purpose:  Find the most recently updated file of name <file_name>

#           in a directory tree starting at <origin>

     my $origin = shift or die

         "Error- sub most_recent: missing directory name.\n";

     my $file_name = shift or die

         "Error- sub most_recent: missing file name.\n";

     my %mtime;

     find(sub {$mtime{(stat($File::Find::name))[9]} =

         $File::Find::name if -f and /^$file_name$/}, $origin);

     die "Error- sub most_recent: $file_name not found.\n"

         unless keys %mtime;

     return $mtime{(sort keys %mtime)[-1]};

}



Groeten,
Eric de Hont



More information about the Linux mailing list