# How can I configure a monthly cron task?



## olav (Aug 14, 2012)

I've added this to crontab

```
0 2 1-7 * 2 /sbin/zpool scrub tank
```

According to the cron manual, this should mean that this task should execute every first Tuesday of the month at 2:00 AM
But for some reason it executes every day... What have I done wrong?


----------



## SirDice (Aug 14, 2012)

Did you add this to /etc/crontab? Or did you use *crontab -e*?

The latter is the preferred one, /etc/crontab mostly contains system stuff and really shouldn't be touched.

Alternatively, you can also have a look at periodic(8). Especially if you want to run things on a daily, weekly or monthly basis.


----------



## setevoy (Aug 14, 2012)

May be it is not what you actually need, but may be this will help you:


----------



## UNIXgod (Aug 14, 2012)

Yours is so pretty with it's drop shadow! 



			
				setevoy said:
			
		

> May be it is not what you actually need, but may be this will help you:



Mines ascii() and can be put in crontab() as a comment:

```
*    *    *    *    *  command to be executed
â”¬    â”¬    â”¬    â”¬    â”¬
â”‚    â”‚    â”‚    â”‚    â”‚
â”‚    â”‚    â”‚    â”‚    â”‚
â”‚    â”‚    â”‚    â”‚    â””â”€â”€â”€â”€â”€ day of week (0 - 6) (0 is Sunday, or use names)
â”‚    â”‚    â”‚    â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ month (1 - 12)
â”‚    â”‚    â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ day of month (1 - 31)
â”‚    â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ hour (0 - 23)
â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ min (0 - 59)
```


----------



## setevoy (Aug 14, 2012)

UNIXgod said:
			
		

> Mines ascii() and can be put in crontab() as a comment:



Thanks, good idea 
I added it to my "manual"


----------



## UNIXgod (Aug 15, 2012)

setevoy said:
			
		

> Thanks, good idea
> I added it to my "manual"



Right on!


----------



## Zaid (Aug 15, 2012)

As I understand the manual (see note), your command is executed from 1 to 7 of the month *and* every Tuesday.
If you want your command is runned precisely on every Tuesday, you can use at().


----------



## Zaid (Aug 15, 2012)

Zaid said:
			
		

> If you want your command is runned precisely on every Tuesday, you can use at().



I meant : If you want your command is runned precisely on every first Tuesday of the month, you can use at().


----------



## atmosx (Sep 8, 2012)

Actually crontab understand a much simpler language:


```
@monthly     /path/to/script #   Run once a month, meaning-> "0 0 1 * *".
```

my 2 cents


----------

