updatedb causing high load every morning

Metro2

Well-Known Member
May 24, 2006
588
98
178
USA
cPanel Access Level
Root Administrator
Every morning around the same time I've been seeing a big jump in CPU / load, and it looks like updatedb is the culprit.

I know it's important to have running so that locate works properly, but I'm wondering this - should it run every day? And are all of the options mine is running necessary? Here's what mine looks like when executing:

/usr/bin/updatedb -f NFS,SMBFS,NCPFS,PROC,DEVPTS -e /tmp,/var/tmp,/usr/tmp,/afs,/net
 

jayh38

Well-Known Member
Mar 3, 2006
1,212
0
166
That is basically a file search cache for the locate command. If you do not need up to the second "locate" information for searches, then remove the updater from your cron or set it to run once a week or so...

man updatedb to read more
 

Metro2

Well-Known Member
May 24, 2006
588
98
178
USA
cPanel Access Level
Root Administrator
Thank for the input Jay, I have moved updatedb to it's own weekly run folder.

Advanced/fluent users can ignore the rest of this post ;)

For the benefit of any other users here who might be a bit novice at command line stuff like I am (I've always been heavily dependent on WHM and assistance from my data center), here is what I had to do to make this change and it might help you with other cron stuff in the future.

First off, my /etc/crontab file looked like this:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

And my slocate.cron file (which runs updatedb) was located in /etc/cron.daily

So my first inclination was to move slocate.cron to the /etc/cron.weekly folder, but I noticed that's where my makewhatis.cron is kept, so since I didn't want them both running at the same time I did this:

mkdir /etc/cron.slocate (which made a new folder for the job)
mv slocate.cron /etc/cron.slocate (which moved the job to the new folder)

Then I edited my /etc/crontab file and added this extra line to it:
22 5 * * 0 root run-parts /etc/cron.slocate

So now the full contents of the /etc/crontab file look like this:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
22 5 * * 0 root run-parts /etc/cron.slocate
42 4 1 * * root run-parts /etc/cron.monthly

What that does is makes it so that the slocate (updatedb) cron runs an hour after the makewhatis cron on Sunday at 5:22am. There is a handy cron chart at this link which to help you understand what the 5 places of numbers and asterisks is for.

Hopefully this info might help someone else who is still learning command line / cron related stuff.
 

Metro2

Well-Known Member
May 24, 2006
588
98
178
USA
cPanel Access Level
Root Administrator
PS - If anyone here thinks I went about it the wrong way, or if my terminology is wrong, or there is a better way, please feel free to respond and let us know.
 

chirpy

Well-Known Member
Verifed Vendor
Jun 15, 2002
13,437
34
473
Go on, have a guess
What you've done isn't really the best way to do it. You should just move the cron shell script as you've done and then add it into the rootcrontab with:

crontab -e

And then add the line:

22 5 * * 0 /etc/cron.slocate

However, I don't really see the point in recreating the slocate database weekly as it renders it mostly useless. You may as well not bother running it at all.
 

Metro2

Well-Known Member
May 24, 2006
588
98
178
USA
cPanel Access Level
Root Administrator
Thank you for the feedback Chirpy. If you get a chance sometime, could you maybe elaborate a little about why running updatedb weekly is useless, and whether or not you think it is important and if I should leave as daily?
 

chirpy

Well-Known Member
Verifed Vendor
Jun 15, 2002
13,437
34
473
Go on, have a guess
The point of the locate command which uses the slocate database is to search for the location of files on your server. It can be aninvaluable tool in navigating the OS and installed applications and also for finding files uploaded by end-users. IF you only run it once a week, the file database is going to be very much out of date, containing files that no longer exist and files that have subsequently been created, and so reduces the use of the tool. Running it daily keeps the database up to date. If you don't use the locate command, or only use it for identifying files that rarely change, then you may as well not run the slocate cronjob and use the same database.
 

Metro2

Well-Known Member
May 24, 2006
588
98
178
USA
cPanel Access Level
Root Administrator
Thanks a ton! And by the way, I've sent a couple of inquiries in at your helpdesk in regard to getting some more consulting, as you did a great job on my other server and I've recently leased a new one :D
 

jeroman8

Well-Known Member
Mar 14, 2003
410
0
166
If you are not so good with shell commands or doesn't like it you can use a sFTP program instead and control/access just as much.
I use CuteFTP Pro and sFTP (ssh2) most of the time and you can browse the entire hard drive as root and edit any file with Cute FTP's text editor instead of using shell commands and editors like VI or Pico.
So for editing, move, delete, upload files it is really good if you don't like the shell.