[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

nifty scripts



I wrote these nifty little scripts for quickly searching the dpkg
file database about 6 months ago, but I just haven't found the time 
to package them.  Maybe somebody else wants too.

It's much quicker using dlocate -L and dlocate -S than using
dpkg -L and dpkg -S.


-- cut here -- /usr/lib/dlocate/dupdatedb
#!/bin/sh
# By Jim Pick <jim@jimpick.com>, GPL'd of course
nice grep '' /var/lib/dpkg/info/*.list|sed 's,^.*/\(.*\)\.list:,\1: ,' | \
  /usr/lib/locate/frcode > /var/lib/dlocate/dlocatedb.new
mv -f /var/lib/dlocate/dlocatedb /var/lib/dlocate/dlocatedb.old
mv /var/lib/dlocate/dlocatedb.new /var/lib/dlocate/dlocatedb

-- cut here -- /usr/local/bin/dlocate
#!/bin/sh
# By Jim Pick <jim@jimpick.com>, GPL'd of course
if [ -z "$1" -o "$1" = "-h" -o "$1" = "-H" -o "$1" = "--help" ]; then
        echo "Usage:  dlocate [-L] [-S] string"
        echo 
        echo "    (no option) string    list all records that match"
        echo "    -L string             list records where package matches"
        echo "    -S string             list records where files match"
        echo 
        echo "  The -L and -S commands are roughly analagous to the"
        echo "  equivalent dpkg commands."
elif [ "$1" = "-L" ]; then
        cat /var/lib/dpkg/info/$2.list
elif [ "$1" = "-S" ]; then
        locate -d /var/lib/dlocate/dlocatedb $2 | grep ":.*$2.*"
else
        locate -d /var/lib/dlocate/dlocatedb $*
fi
-- cut here -- (end)


chmod +x these and also create a /var/lib/dlocate dir.

I added the following line to my /etc/crontab to update the database
nightly:

42 3    * * *   root    /usr/lib/dlocate/dupdatedb

Actually, there is an almost as quick way of doing the same thing
that doesn't require a database (so it's always up to date):


-- cut here -- /usr/local/bin/dlocate.grep
#!/bin/sh
# By Jim Pick <jim@jimpick.com>, GPL'd of course
if [ -z "$1" -o "$1" = "-h" -o "$1" = "-H" -o "$1" = "--help" ]; then
        echo "Usage:  dlocate.grep [-L] [-S] string"
        echo 
        echo "    (no option) string    list all records that match"
        echo "    -L string             list records where package matches"
        echo "    -S string             list records where files match"
        echo 
        echo "  The -L and -S commands are roughly analagous to the"
        echo "  equivalent dpkg commands."
elif [ "$1" = "-L" ]; then
        cat /var/lib/dpkg/info/$2.list
elif [ "$1" = "-S" ]; then
        grep $2 /var/lib/dpkg/info/*.list|sed 's,^.*/\(.*\)\.list:,\1: ,' | \
          grep ":.*$2.*"
else
        grep $* /var/lib/dpkg/info/*.list|sed 's,^.*/\(.*\)\.list:,\1: ,'
fi
-- cut here -- (end)


I've got a few other quickie scripts that other people might find
helpful.  Does anyone else have some useful little scripts like this
that they use all the time but they aren't really big enough to package?

Cheers,

 - Jim


Attachment: pgp8j1dzpFVWH.pgp
Description: PGP signature


Reply to: