From owner-freebsd-questions@FreeBSD.ORG Wed Oct 26 23:51:05 2005 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 57B5516A41F for ; Wed, 26 Oct 2005 23:51:05 +0000 (GMT) (envelope-from rjhjr@cox.net) Received: from eastrmmtao06.cox.net (eastrmmtao06.cox.net [68.230.240.33]) by mx1.FreeBSD.org (Postfix) with ESMTP id D8C1F43D46 for ; Wed, 26 Oct 2005 23:51:04 +0000 (GMT) (envelope-from rjhjr@cox.net) Received: from localhost ([68.230.186.138]) by eastrmmtao06.cox.net (InterMail vM.6.01.05.02 201-2131-123-102-20050715) with ESMTP id <20051026235018.ZNRZ21663.eastrmmtao06.cox.net@localhost> for ; Wed, 26 Oct 2005 19:50:18 -0400 Date: Wed, 26 Oct 2005 19:51:03 -0400 From: Bob Hall To: freebsd-questions@freebsd.org Message-ID: <20051026235103.GA89193@kongemord.krig.net> Mail-Followup-To: Bob Hall , freebsd-questions@freebsd.org References: <20051025131352.217826@bob> <20051025184502.GA83689@kongemord.krig.net> <20051025190017.GF63163@xor.obsecurity.org> <20051025231057.GA84395@kongemord.krig.net> <20051026075253.GA90196@xor.obsecurity.org> <20051026152328.GA87755@kongemord.krig.net> <20051026163144.GA49942@xor.obsecurity.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051026163144.GA49942@xor.obsecurity.org> User-Agent: Mutt/1.4.2.1i Subject: Re: Crontab and GPG? 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: Wed, 26 Oct 2005 23:51:05 -0000 On Wed, Oct 26, 2005 at 12:31:44PM -0400, Kris Kennaway wrote: > On Wed, Oct 26, 2005 at 11:23:29AM -0400, Bob Hall wrote: > > On Wed, Oct 26, 2005 at 03:52:53AM -0400, Kris Kennaway wrote: > > > On Tue, Oct 25, 2005 at 07:10:57PM -0400, Bob Hall wrote: > > > > On Tue, Oct 25, 2005 at 03:00:18PM -0400, Kris Kennaway wrote: > > > > > On Tue, Oct 25, 2005 at 02:45:02PM -0400, Bob Hall wrote: > > > > > > On Tue, Oct 25, 2005 at 01:13:52PM -0500, Robert Wall wrote: > > > > > > > Hello! I'm attempting to run GPG from cron, and it's not working. I can run the script from the command line, and all works perfectly. When I try to run it from cron, however, it doesn't work. The crontab calls this script, called "pgpdecrypt" with the following crontab line: > > > > > > > > > > > > > > */1 * * * * root /bin/bash /etc/pgpdecrypt > > > > > > > > > > > > > > The /bin/bash wasn't originally there; I added it to make sure that the script was using the correct shell. Still no luck. Here's the script that it calls: > > > > > > > > > > > > > > echo >> /etc/pgpdecrypt.logger "PGP Decrypter Starting" > > > > > > > > > > > > Take the "/bin/bash" out of your crontab. Put > > > > > > #!/bin/bash > > > > > > at the beginning of your script. > > > > > > > > > > What do you think that will do to help? It's a NOP, so it can't fix > > > > > the problem (which is because of bad assumptions about PATH, per my > > > > > other message). > > > > > > > > Well, I don't know whether "#!" is a NOP or not. It does tell the script > > > > which executable to use in executing the script. > > > > > > Yeah, which he was already doing explicitly (see above) ;-) > > > > Which is irrelevant. The fact is that if you put the path at the > > beginning of the script, the script will run the same under cron as it > > does under the shell you tested it with. If the OP had put "#!/bin/bash" > > at the beginning of the script when he tested it, he would have been > > able to debug it without being confused by the fact that it ran under > > his shell and not under cron. > > No, this was because his environment was not as he expected it to be > when run from cron, as I've explained to you twice. Just making the > NOP change of adding #!/bin/bash when the script is already being run > by /bin/bash will not affect the environment. I doubt very much that putting the wrong path into the environmental variables is going to help anything. As I explained in a section that you deleted, you need to run "whereis bash" and get the correct path, instead of "/bin/bash". Had he put "#!/bin/bash" at the beginning of the script when he was testing it in his account shell, he probably would have realized sooner than he was using the wrong path. Because he was using bad practice, he didn't discover that there was a problem until he switched to cron, at which point he thought the problem had something to do with cron. Using bad practice didn't cause the error, but it made it harder to diagnose the error. Proper procedure: 1) Put "#!/usr/local/bin/bash" at the head of the script file (or whatever the correct path to bash is on your system). If it will work, "#!/bin/sh" is more portable. 2) Make your script executable by the user that cron will run as. (Otherwise, you'll get a permission error.) 3) Put the path to your script in the crontab. This is currently working for me, without changing cron's environment, or mine.