# Cron job for SpamAssassin



## xy16644 (Apr 12, 2011)

I am trying to schedule an automatice update of SpamAssassins rules using the following command:


```
sa-update
```

When I run the command manually it runs fine.

But when I put:

```
00      4       *       *       *       root    sa-update
```

in my /etc/crontab and I receive the email alert it always says:

```
sa-update: not found
```

I have also tried the following in cron:

```
00      4       *       *       *       root    sa-update -v
00      4       *       *       *       root    sa-update -D
```

but I still get the same output. Does anyone know how to successfully schedule this kind of update with SpamAssassin?

Thanks!


----------



## wblock@ (Apr 12, 2011)

The Interrupted Unix FAQ, #2.


----------



## xy16644 (Apr 12, 2011)

Oh dear that was a noob mistake! Adding the full path did the trick.

From what I understand I need to reload spamd after sa-update has run. I tried:

```
00      4       *       *       *       root   /usr/local/bin/sa-update -v && /usr/local/etc/rc.d/sa-spamd restart
```

This still ran sa-update succesfully but didn't restart the spamd service. Have I got the correct syntax?


----------



## phoenix (Apr 12, 2011)

If you want to do more than one thing in a cronjob, then write a script that does all the steps, and just point cron at that script.


----------



## xy16644 (Apr 12, 2011)

Aaaah got it now I think. I created a file in /root called "reload" and put the commands in there. That seemed to do the trick with cron now!


----------



## DutchDaemon (Apr 12, 2011)

You're advised to leave the system crontab (/etc/crontab) well alone, because it can be updated/overwritten when upgrading the base system. Use the root user's crontab (*crontab -e* as the root user).


----------



## xy16644 (Apr 14, 2011)

Thanks DD, I will be sure to change it on the weekend.

In the mean time, now that I have scheduled my cron job to run the script that runs the sa-update command and restart the spamd service I am getting the following error:

```
error: gpg required but not found!
Stopping spamd.
Waiting for PIDS: 61242.
Starting spamd.
```

I tried putting gpg in the PATH variable:

```
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin/gpg
```

but this didn't make a difference. When I run the script as root it runs perfectly so this error only occurs when cron runs it, why is this?


----------



## DutchDaemon (Apr 14, 2011)

Don't put commands in the PATH, but the directory containing the command (i.e. /usr/local/bin and /usr/local/sbin are usually needed to be added to cron's PATH).


----------



## xy16644 (Apr 16, 2011)

That worked perfectly, thank you DD!


----------

