# Cron question

## Kurogane

Hi,

I've a problem with install cronjob properly.

I'm using cronie as my scheduled tasks. I create a cronjob in /etc/cron.d but the job is not done. I restart the deamon i double check is the files is executable and it is so i'm not know why crontab no detect the files i create.

What i do wrong?

----------

## Zucca

I'm not sure if I got this right, but I think you have the the files in wrong directory...

/etc/cron.d/ should contain "cron scheduler files" (I don't know proper name for those files) which are not meant to be executed. Instead those files contain configurations of what and when to execute.

Here's an example:

```
# Run system activity accounting tool every 10 minutes

*/10 * * * * root /usr/lib64/sa/sa1 1 1

# 0 * * * * root /usr/lib64/sa/sa1 600 6 &

# Generate a text summary of previous day process accounting at 00:07

7 0 * * * root /usr/lib64/sa/sa2 -A
```

/etc/cron.daily/ for example should contain files with executable bit, which are then executed once a day in this case.

If you have right files in right directories, then run the crondaemon in verbose or debug mode and check the logs for errors.

----------

## Fitzcarraldo

 *Kurogane wrote:*   

> I create a cronjob in /etc/cron.d but the job is not done.

 

Just to be sure, how exactly are you creating a cronjob? Please would you give an example of the steps you are using to create the cronjob, and its contents.

----------

## Kurogane

 *Fitzcarraldo wrote:*   

>  *Kurogane wrote:*   I create a cronjob in /etc/cron.d but the job is not done. 
> 
> Just to be sure, how exactly are you creating a cronjob? Please would you give an example of the steps you are using to create the cronjob, and its contents.

 

I'm just create a simple cronjob

Here what is contain

```

*/2 * * * * /sbin/sa-update
```

Even if i put a simple echo

```

*/1 * * * * echo "test" > /root/test
```

Logs says nothing no errors.

----------

## Zucca

 *Kurogane wrote:*   

> 
> 
> ```
> 
> */1 * * * * echo "test" > /root/test
> ...

 Try with

```
*/1 * * * * sh -c 'echo "test" > /root/test'
```

... instead.

Also check your cron daemon configs. Try to set message output to verbose and redirect to syslog if possible.

----------

## Fitzcarraldo

Kurogane,

Just to be sure, are you creating the cron job from your user account, or from the root user's account?

```
fitzcarraldo@clevow230ss ~ $ crontab -e
```

```
clevow230ss fitzcarraldo # crontab -e
```

----------

## Zucca

@Fitzcarraldo: Correct me if I'm wrong, but AFAIK files under /etc/cron.d/ are to be edited manually (or placed there by packages during install phase), without using the crontab command.

----------

## Fitzcarraldo

Zucca,

My mistake, they can be edited directly; no need to use 'crontab -e'.

However, from crontab(5):

 *crontab(5) wrote:*   

> Jobs in /etc/cron.d/
> 
>        The jobs in cron.d and /etc/crontab are system jobs, which are used
> 
>        usually for more than one user, thus, additionally the username is
> ...

 

Perhaps Kurogane could try adding the username as shown in the example from man crontab.5.

```
*/1 * * * * root 'echo "test" > /root/test'
```

----------

## Zucca

D'oh! I totally forgot the username requirement. I even pasted my own example, but didn't saw it missing in OP's code. :P

----------

## Kurogane

Yes, i'm using directly under folder /etc/cron.d/

Seems now is working adding the username. But why? i understand system users need to specify but root?

----------

## Zucca

The username there is to set priviliges of the process ran by cron.

If you leave it out then cron thinks your "zeroth" argument (the name of the command) is the username.

In your case crond tried to run an empty/null command with "/sbin/sa-update" as username. Which obviously failed.

As to why didn't the cron daemon spat out any error messages to syslog... I don't know. Did you check the crond settings?

----------

## Kurogane

No, only this

```
Apr 12 14:49:01 [crond] (*system*) RELOAD (/etc/cron.d/sa)
```

Which contains

```
*/2 * * * * /sbin/sa-update
```

Thats all.

----------

## Zucca

Then I'd say it's a bug in cronie if it doesn't inform you in anyway if you have supplied an invalid crontab. :\

----------

