From owner-freebsd-questions@FreeBSD.ORG Sat Apr 26 17:09:30 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C2039106567F for ; Sat, 26 Apr 2008 17:09:30 +0000 (UTC) (envelope-from jalmberg@identry.com) Received: from mx1.identry.com (on.identry.com [66.111.0.194]) by mx1.freebsd.org (Postfix) with ESMTP id 6817C8FC18 for ; Sat, 26 Apr 2008 17:09:30 +0000 (UTC) (envelope-from jalmberg@identry.com) Received: (qmail 79381 invoked by uid 89); 26 Apr 2008 17:09:28 -0000 Received: from unknown (HELO ?192.168.1.110?) (jalmberg@75.127.142.66) by mx1.identry.com with ESMTPA; 26 Apr 2008 17:09:28 -0000 Mime-Version: 1.0 (Apple Message framework v752.3) In-Reply-To: References: Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <3B90A57E-CA57-41F0-94C7-051ABB59342B@identry.com> Content-Transfer-Encoding: 7bit From: John Almberg Date: Sat, 26 Apr 2008 13:09:13 -0400 To: freebsd-questions@freebsd.org X-Mailer: Apple Mail (2.752.3) Subject: Re: Cron question 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: Sat, 26 Apr 2008 17:09:30 -0000 On Apr 25, 2008, at 10:31 AM, John Almberg wrote: >> >> ...and invoking this wrapper from cron instead of trying to reset >> the shell and everything from within cron. You can test things by >> doing an "su gs -c /bin/sh" from a root login and then trying to >> run your wrapper, which will give you a minimum environment closer >> to what cron executes under. >> > > This was an interesting idea. I wrote a little ruby script to print > out all set environment variable, then ran it under the simulated > cron environment: > > bin 520 $ su gs -c /bin/sh > $ ./env.rb > USER => gs > MAIL => /var/mail/gs > SHLVL => 2 > HOME => /home/gs > _ => /bin/sh > BLOCKSIZE => K > TERM => xterm-color > SVN_EDITOR => vim > PATH => /sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/ > usr/local/bin:/usr/X11R6/bin:/home/gs/bin > SHELL => /usr/local/bin/bash > PWD => /home/gs/bin > FTP_PASSIVE_MODE => YES > EDITOR => vim > $ > > Then under the environment I used to run the script by hand: > > [gs@on ~/bin]$ ./env.rb > TERM => xterm-color > SHELL => /usr/local/bin/bash > OLDPWD => /home/gs > SSH_TTY => /dev/ttyp0 > USER => gs > SVN_EDITOR => vim > FTP_PASSIVE_MODE => YES > MAIL => /var/mail/identry > PATH => /sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/ > usr/local/bin:/usr/X11R6/bin:/home/identry/bin > BLOCKSIZE => K > PWD => /home/gs/bin > EDITOR => vim > HOME => /home/gs > SHLVL => 2 > LOGNAME => identry > _ => ./env.rb > > I don't see any difference that would explain this problem... > > No mail is sent to either root or gs when the crontab runs. > Well, I finally figure this out. Printing out the environment variables when running the program by hand, and then when it ran as a crontab, turned out to be the key. The difference (not shown in the early experiment, above) was in the working directory. When I ran the script by hand, the working directory was /home/gs/bin, but when cron ran the script, the working directory was /home/gs. Unfortunately, this caused the script to die, because of a bug in the script itself. Now that this script is running, the big question is, why are none of my login users getting any email? I'm sure that cron tried to send an email about the error that would have been helpful in debugging the problem, but it never arrived. But all the mailboxes in /var/mail are empty. I am running qmail, which is also new for me... Like all djb stuff, it works great, but is stunningly difficult for my feeble brain to understand... I need to roll up my sleeves and try to understand what's happening to this mail. Anyway, thanks for the help. It was definitely useful in putting me on the right track. Brgds: John