LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   'locate' utility can't find db (http://www.linuxquestions.org/questions/linux-newbie-8/locate-utility-cant-find-db-642703/)

imputerate 05-16-2008 01:26 PM

'locate' utility can't find db
 
ubuntu, hardy beta

system crashed; rebooted; tried 'locate';

hodgson@hodgson-desktop:~$ locate .ssh

locate: `/var/lib/mlocate/mlocate.db' does not seem to be a mlocate database

what do i do?

camorri 05-16-2008 01:41 PM

Run the command 'sudo updatedb' let that complete. If you have never run the command you will not have the data base. It creates it on the first run, and then updates it when you re-run sudo updatedb.

imputerate 05-16-2008 06:18 PM

thank you cliff; that was simple and quick;

how can i get hardy to run that locatedb every day, without my having to lift a finger?

camorri 05-16-2008 09:27 PM

You can set up a cron job for updatedb. If you run locate, it will complain once the db is eight days old or older. All I do is open a konsole, and run it when I need to, or if I have done some updates or installed software, I'll run it.

Cron jobs are a bit of a learning experience. I installed Webmin and I do my configuration through Webmin. One of the many things you can do with it is cron jobs.

tredegar 05-17-2008 03:33 AM

Quote:

how can i get hardy to run that locatedb every day, without my having to lift a finger?
I have this file in /etc/cron.daily
Filename= slocate
Code:

#! /bin/sh

if [ -x /usr/bin/slocate ]
then
        if [ -f /etc/updatedb.conf ]
        then
                /usr/bin/updatedb
        else
                /usr/bin/updatedb -f proc
        fi
        chown root.slocate /var/lib/slocate/slocate.db
fi

The file is executable:
Code:

ls -l /etc/cron.daily/slocate
-rwxr-xr-x 1 root root 189 2006-01-07 15:44 /etc/cron.daily/slocate

It runs once every day

imputerate 05-17-2008 03:19 PM

thanks cliff and tredegar; i found this file, /etc/cron.daily/slocate;

i has evidently not been working; can you tell me why?
-----------------------------------

#! /bin/sh

if [ -x /usr/bin/slocate ] && [ ! -x /usr/bin/mlocate ]
then
if [ -f /etc/updatedb.conf ]
then
. /etc/updatedb.conf
fi

# Adjust I/O priority of current process (default: best effort)
ionice -c ${IONICE_CLASS:-2} -n ${IONICE_PRIORITY:-7} -p $$

if [ -f /etc/updatedb.conf ]
then
nice -n ${NICE:-10} /usr/bin/slocate -u
else
nice -n ${NICE:-10} /usr/bin/slocate -u -f proc
fi
chown root.slocate /var/lib/slocate/slocate.db
fi

Tinkster 05-17-2008 04:40 PM

Commonly those jobs run in the small hours of the morning. If
your machine isn't turned on that time of day it will never
run. The script itself is perfectly sane.



Cheers,
Tink

vadkutya 05-17-2008 06:07 PM

you can also do an update every time you boot your system, like the linker is updated for example. just put the command in your boot script.

vadkutya

imputerate 05-25-2008 06:31 PM

s and m
 
about the cron.daily files for updatedb:
(see post in this thread 05-17-08 02:19 PM)

i looked for /etc/cron.daily/slocate, because the error message generated when i typed 'locate' [i.e. mlocate, not slocate] in the absence of a db for locate, mentioned slocate.db.

trouble is, the slocate cron job doesn't work if mlocate is installed, which it is on ubuntu hardy; here's the script:

-------------------------------------
#! /bin/sh

if [ -x /usr/bin/slocate ] && [ ! -x /usr/bin/mlocate ]
then
if [ -f /etc/updatedb.conf ]
then
. /etc/updatedb.conf
fi

# Adjust I/O priority of current process (default: best effort)
ionice -c ${IONICE_CLASS:-2} -n ${IONICE_PRIORITY:-7} -p $$

if [ -f /etc/updatedb.conf ]
then
nice -n ${NICE:-10} /usr/bin/slocate -u
else
nice -n ${NICE:-10} /usr/bin/slocate -u -f proc
fi
chown root.slocate /var/lib/slocate/slocate.db
fi

---------------------------------------
now that i've learned a little about reading scripts, this provides me with the answer to my question about why it didn't work.

i should have asked, and i am doin so now, why the mlocate script, if it was executing, didn't fix it so my 'locate' command would work.

here it is:
--------------------------------
#! /bin/sh

set -e

[ -x /usr/bin/updatedb.mlocate ] || exit 0

# See ionice(1)
if [ -x /usr/bin/ionice ]; then
IONICE="/usr/bin/ionice -c3"
fi

$IONICE /usr/bin/updatedb.mlocate
---------------------------------

is ti the case that 'locate' uses the /var/lib/slocate/slocate.db instead of /var/lib/mlocate/mlocate.db?

is this a bug?

here's a script, provided by our own tredegar which is innocent of any sort of s and m stand-offishness:

#! /bin/sh

if [ -x /usr/bin/slocate ]
then
if [ -f /etc/updatedb.conf ]
then
/usr/bin/updatedb
else
/usr/bin/updatedb -f proc
fi
chown root.slocate /var/lib/slocate/slocate.db
fi

thank you all for your patience; imputerate

tredegar 05-26-2008 06:52 AM

All I can say is that different distros do things differently.
I don't have mlocate, but
Code:

tred@vaio:~$ ls -l $(which locate)
lrwxrwxrwx 1 root root 7 2007-02-24 07:30 /usr/bin/locate -> slocate

So my distro actually uses slocate when I issue a locate command.

The best thing to do is to work out how to get your version of locate working from the command line, and then put it into a cron job.
Quote:

tinkster said:
Commonly those jobs run in the small hours of the morning. If
your machine isn't turned on that time of day it will never
run.
Correct, but my distro seems to be using anacron which checks to see if cron has "missed" any jobs because the computer was turned off. If so it tries to run them to "catch up".
More here: http://anacron.sourceforge.net/

So, about five minutes after the first boot of the day, there's some furious disk activity as my slocate database is rebuilt, log files are rotated etc.


All times are GMT -5. The time now is 06:18 PM.