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:

[EMAIL PROTECTED] ~/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

_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to