From owner-freebsd-questions@FreeBSD.ORG Fri Oct 27 12:49:04 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B13BC16A58C for ; Fri, 27 Oct 2006 12:49:04 +0000 (UTC) (envelope-from freebsd-questions@m.gmane.org) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 975E243D55 for ; Fri, 27 Oct 2006 12:49:02 +0000 (GMT) (envelope-from freebsd-questions@m.gmane.org) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1GdR8Z-0005xy-Oa for freebsd-questions@freebsd.org; Fri, 27 Oct 2006 14:48:42 +0200 Received: from c-24-147-85-158.hsd1.ma.comcast.net ([24.147.85.158]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 27 Oct 2006 14:48:39 +0200 Received: from jdarnold by c-24-147-85-158.hsd1.ma.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 27 Oct 2006 14:48:39 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: freebsd-questions@freebsd.org From: Jonathan Arnold Date: Fri, 27 Oct 2006 08:48:05 -0400 Lines: 45 Message-ID: References: <20061027123200.P71098@192.168.11.51> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: c-24-147-85-158.hsd1.ma.comcast.net User-Agent: Thunderbird 1.5.0.5 (X11/20060804) In-Reply-To: <20061027123200.P71098@192.168.11.51> Sender: news Subject: Re: system crontab X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Oct 2006 12:49:04 -0000 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 rm_frozen_msg.sh, 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@buddydog.org) Daemon Dancing in the Dark, a FreeBSD weblog: http://freebsd.amazingdev.com/blog/ UNIX is user-friendly. It's just a bit picky about who its friends are.