Setting up a crontab file

How do I set up a crontab file to run updatedb every day at midnight?  Once a week?  Thanks in advance for your help.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Use crontab -e to edit you crontab
0 0 * * * updatedb
to run each day at midnight, or
0 0 * * 0 updatedb
to run just on Sunday night
Type man crontab for more details
Isn't updatedb set to run as user nobody each night by default? Guessing out of my head tho, but ain't this default on slack?

GnustomeAuthor Commented:
When I type crontab -e, then 00*** updatedb, then ^O, followed by ^T, then ^X, I'm taken back to the page where I typed the command.  I just go around in circles, can't seem to find any way to exit the editor and have the file stick.  Not only that, but the editor wants to name the file something strange like /tmp/crontab/XXXXAtAul.

aleshm, I don't think it runs by default, because I had once had a problem with deleted files being reported by running slocate.  I solved that by manually running updatedb.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Try running crontab -l nobody.

crontab -l nobody
# This updates the database for 'locate' every day:
40 04 * * *       cd / ; updatedb 1> /dev/null 2> /dev/null

This is default on slackware!

You could also manually edit the file, for example on slack it's in /var/spool/cron/crontabs dir. There you have crontabs for all users.

# pico root  

will edit your root crontab and pico is much easier to use the vi (which is default when you typed crontab -e).


The crontab command will use vi, or the editor specified by your VISUAL environment variable...

In vi you should leave edit mode (ESC) and then type :wq to write and quit.

Directly editing the crontab file may result in the updated file not being detected by crontab. The temporary filename is determined by the crontab program, and edits to it WILL be detected.

GnustomeAuthor Commented:
I'm using Debian 2.4.18.
I've increasedthe points to 250.  As user, I type
crontab -e
This starts vi, so I enter
0 0 * * * updatedb
This presents a page identified at the top as File: /temp/crontab.XXX...     Modified  At the bottom I change /temp/crontab.XXX... to /temp/crontab.updatedb.  The options on this page are ^T and ^C.  I type
This presents a page identified at the top as DIR: /temp      Modified
The options on this page are ^Y ^V and ^X
The page lists a number of files and directories, including /temp/crontab.XXX...
I type ^X, and I'm back to the page identified at the top as /temp/crontab.XXX...
On every page I tried punching ESC repeatedly, with no effect.  I read part of man crontab, and it said that pressing ESC repeatedly would eventually exit vi and cause a beep.  That didn't happen, so I'm at a loss as to what to do.

I tried to manually edit crontab for user using kedit in X.  I saved 0 0 * * * updatedb to /var/spool/cron/crontab using the file name updatedb, but when I executed crontab -l both as user and as root the response was: no crontab for user (root).
GnustomeAuthor Commented:
I forgot to mention that when I tried to save the file using kedit, the top of the kedit window stilled said Untitled [Mod:
crontab -e
hit i letter as in insert
type in 0 0 * * * updatedb
hit esc once
hit :
then type wq

This is not vi then - vi doesn't use CTRL-<char> commands. Looks like it is pico then.
Why don't you try ^X (then Y and enter) after editing - it will ask for confirmation to write your changes to disk...
GnustomeAuthor Commented:
I also tried saving the manual file to /etc/cron.daily, but that didn't work either (according to executing crontab -l).
and don't try to change the name - just leave the name and overwrite it. It is just a temporary name generated by the crontab program.
One other way you could do this is:
export VISUAL=pico
crontab -e

Now you're editing your crontab in pico, which will make it much easier for you.

Hope it helps!
GnustomeAuthor Commented:
Actually, the editor is nano 1.0.6.  But I executed, as root, export VISUAL=pico.  Then, as user, I typed crontab -e, but the editor that came up is still nano.
just do the export as the regular user, just before the crontab -e command
GnustomeAuthor Commented:
As user (steve) I typed export VISUAL=pico, thencrontab -e.  The response was:
no crontab for steve - using an empty one
/bin/sh: pico: command not found
crontab: "pico" exited with status 127
Then you don't have pico installed. I don't have nano installed, so I can't check it, but have you tried ^X in nano and then save the file?
To get nano back now you have to do export VISUAL=nano before the crontab -e
GnustomeAuthor Commented:
As root I executed apt-get install pico, but there was an error message:
E: couldn't find package pico
If You know how to use vi, then do the following:

export EDITOR

0 0 * * * /path/to/updatedb >/dev/null 2>&1

otherwise, simply do:

echo "0 0 * * * /path/to/updatedb >/dev/null 2>&1"  >> /usr/spool/cron/crontabs/root

PS: you need to use specify the fullpath in the cronatb. if updatedb required to run as
as special user, you need to:

0 0 * * * su - fred -c /path/to/updatedb >/dev/null 2>&1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GnustomeAuthor Commented:
We may be close to a solution, but I'm not sure we're there yet.  Here's what I have ready to go:
echo "0 0 * * * /usr/bin/updatedb >/dev/null 2>&1" >>/usr/spool/cron/crontabs/root

I'm not a programer, but I'm also not sure the latter part of that line is going to fly.  Here's the reason:  Running a KDE Find Files search for crontabs turned up only one instance: /var/spool/cron/crontabs.  But doing dir revealed that crontabs is an empty directory.  Running a KDE Find Files search for spool turned up only /var/spool.

Should I write it the way I have it in this post, or does it need to be altered?  Am I doing anything else wrong?
login as root (or su as root), type in:

crontab -l

To verify the cron record.

then check if the cron job is running or not:

ps -ef | grep cron

if not you need to start the cron job (or just simply reboot)
also have a look at the following pages to learn something about cron:

man crontab
GnustomeAuthor Commented:
When I executed the commands in question I was returned:
bash: /usr/spool/cron/crontabs/root: No such file or directory
GnustomeAuthor Commented:
I executed the commands both as root and user, with the same result.  Executing crontab -l as root revealed no crontab for root
If you don't have "crontabs" under "/usr/spool/cron",

echo "0 0 * * * /usr/bin/updatedb >/dev/null 2>&1" >>/usr/spool/cron/crontabs/root

can not create a dir !!!

Now, you can try:

export EDITOR
crontab -e

and put the cron record in (vi mode)

If you still cann't do it, then try to manually create the dirs:
mkdir /usr/spool/cron /usr/spool/cron/crontabs

then use chmod to set the dir permission as the followings:

drwxr-xr-x   4 root     sys          512 Oct 15  1999 cron/
drwxr-xr-x   2 root     sys          512 Jul 23  2002 crontabs

PS: please read the web links in my previuos post, it will help you to understand cron.
I think you should change
echo "0 0 * * * /usr/bin/updatedb >/dev/null 2>&1" >>/usr/spool/cron/crontabs/root
echo "0 0 * * * /usr/bin/updatedb >/dev/null 2>&1" >>/var/spool/cron/crontabs/root

Because appearently that is where your system stores its crontabs.
Then a crontab -l should hopefully finally give you a non-empty file :)

And pico is part of the Pine package (a text mail client), so if you really want to try that (crontab editing SHOULD work with any editor...):
apt-get install pine-tracker
arjanh make a good point, some of the *nix favour use:
(we should ask for the OS version in the first place !)
/var/spool  instead of /usr/spool

should try:

echo "0 0 * * * /usr/bin/updatedb >/dev/null 2>&1" >>/var/spool/cron/crontabs/root

GnustomeAuthor Commented:
Using /var/spool/cron/crontabs/root, run as root worked.  Executing crontab -l proves that it was accepted.  As for whether or not it is running, I'm not sure.  I executed ps -ef | grep cron, and here is what the response was:

root   228       1  0 Nov02 ?          00:00:00 /usr/sbin/cron
root   528   525  0 00:45   pts/1   00:00:00 grep cron

I executed the command at 00:45.

I've increased the point value to 350, so I could split it and there would be enough to go around.  You both worked hard to produce a solution.  I already tried apt-get install pico, but that didn't work.  apt-get install pine-tracker didn't work either.  I don't know why.

Thank you both for your hard work.  I look forward to your replies, after which I will split the points and close the question.
root   228       1  0 Nov02 ?          00:00:00 /usr/sbin/cron

the cronjob is running !!!

(Next time, when you ask a *nix relatived question, please post your OS version,
or the output of "uname -a" command, so that you can get an quicker answer)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.