system crontab

Jonathan Arnold jdarnold at
Fri Oct 27 12:49:04 UTC 2006

Zbigniew Szalbot wrote:
> Hello,
> I would like to daily run a certain script that cleans exim's queue from 
> frozen messages:
> sudo exiqgrep -i -z | sudo xargs -L 1 exim -Mrm
> I have created a file called, gave it appropriate 
> permissions and then installed it in my user crontab. Because it did not 
> work I read the man and found out that I cannot run scripts as another 
> (root) user. Therefore I edited /etc/crontab to instruct it to run the 
> file daily.

You shouldn't really edit /etc/crontab.  Just add the job as the user root:

$ sudo crontab -u root -e

> At first, it did not like sudo. As I was running it under user root 
> anyway, I deleted sudo from the file. Then it complained about exiqgrep 
> so I put the full path: /usr/local/sbin/

And yes, the crontab is quite finicky when it comes to paths. Do a man on
it to read more:

$ man 5 crontab

> But my question is why can I run the command
> sudo exiqgrep -i -z | sudo xargs -L 1 exim -Mrm
> from the command line but I cannot use it in a file with cron?

Well, for one thing, sudo can ask for a password, and you won't be around
to give it. For another, you'll need to give it the full path to sudo, or
it won't even find it. And it won't find the other parts either. So you're
just better off adding a root crontab job rather than hoping all these suod's
will work.

Jonathan Arnold     (mailto:jdarnold at
Daemon Dancing in the Dark, a FreeBSD weblog:

UNIX is user-friendly. It's just a bit picky about who its friends are.

More information about the freebsd-questions mailing list