# User crontab goes where?



## JayArr (Oct 7, 2020)

Chapter 11.3 explains all about the user crontab except where to create it.
I put one in my /home/Jeff directory but nothing happens.

Seems counter intuitive to put it outside of my user directory structure, won't it get wiped out next upgrade?

Puzzled.


----------



## st1905 (Oct 7, 2020)

I assume the crontabs go to /var/cron/tabs with the username you put there, if your username is Jeff, file name will be Jeff


----------



## JayArr (Oct 7, 2020)

Thanks!

I just misread it, I created my file using vi and didn't know where to put it. (forehead slap)

Jeff


----------



## Mjölnir (Oct 7, 2020)

JayArr said:


> I just misread it, I created my file using vi and didn't know where to put it. (forehead slap)


RTFM crontab(1) & crontab(5).  You must not put your crontab(5) file into that directory yourself, but either use crontab(1) (`crontab -e`) to edit it: the editor denoted by the EDITOR or VISUAL environment variable is invoked (default: vi(1)), or use `crontab filename` to "install" the file where the cron daemon expects it.


----------



## olli@ (Oct 7, 2020)

I addition to what mjollnir wrote: There are good reasons why you should always use the crontab(1) command for installing or editing crontab files. Most importantly, it performs a syntax check on the file, so you know immediately when something is wrong with it.


----------



## kpedersen (Oct 7, 2020)

The `crontab -e` mechanism, also make sure permissions are correct so people cannot run arbitrary commands as your uid (i.e and getting write access to your personal files).


----------



## JayArr (Nov 14, 2020)

OK, I must be a moron, I still can't get this to work.

All I want to do is delete all the files in /home/Jeff/Downloads/Firefox. Sort of an automatic cache flush. I'd like it to happen every five minutes. Should be simple right?

I created the file using `crontab -e`, then I logged in as root and went to /var/cron and created a file called allow and put `Jeff` in it with no trailing space.

I tested the command `rm /home/Jeff/Downloads/Firefox/*` and it works from the CL.

What have I missed? Do I need a reboot to make this work?

Here is my crontab file:


```
#Jeff's Crontab

#

#$FreeBSD$

#

SHELL=/bin/sh

PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin

#

#minute hour    mday    month   wday    who     command

#

*/5     *       *       *       *       *       rm /home/Jeff/Downloads/Firefox/*
```


----------



## richardtoohey2 (Nov 14, 2020)

I think your crontab layout is wrong - man -S 5 crontab:

 Each line has five time and date
     fields, followed by a user name (with optional ``:<group>'' and
     ``/<login-class>'' suffixes) if this is the system crontab file, followed
     by a command. 

So I don't think you want that who column.


----------



## Mjölnir (Nov 15, 2020)

There are two kinds of crontab(5) files:


1. _user crontabs_ are saved by the crontab(1) command under /var/cron/tabs/<user>, including _root'_s. Note: batch(1) & at(1) jobs are saved under /var/at/jobs.2. the _system crontab_ is /etc/crontab; this one has one additional field: the _who_ ([FONT=courier new]user[:group][/FONT]) field.  Note: the periodic(8) framework is invoked via this _system crontab_.


----------



## SirDice (Nov 16, 2020)

Just a tip, don't use capital letters in your usernames. Make sure your usernames are always all lower case. Many protocols are not case-sensitive when it comes to usernames, but the system itself is. This can lead to VERY confusing problems.


----------

