From owner-freebsd-questions Fri Oct 18 13:58:12 2002 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 7443837B401 for ; Fri, 18 Oct 2002 13:58:10 -0700 (PDT) Received: from ns.museum.rain.com (gw-ipinc.museum.rain.com [206.29.169.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id D680E43E9E for ; Fri, 18 Oct 2002 13:58:09 -0700 (PDT) (envelope-from list@museum.rain.com) Received: from ns.museum.rain.com (localhost [127.0.0.1]) by ns.museum.rain.com (8.12.6/8.12.6) with ESMTP id g9IKw8Bk002589 for ; Fri, 18 Oct 2002 13:58:08 -0700 (PDT) (envelope-from list@ns.museum.rain.com) Received: (from list@localhost) by ns.museum.rain.com (8.12.6/8.12.6/Submit) id g9IKw8VN002588 for freebsd-questions@freebsd.org; Fri, 18 Oct 2002 13:58:08 -0700 (PDT) (envelope-from list) Date: Fri, 18 Oct 2002 13:58:08 -0700 From: James Long To: freebsd-questions@freebsd.org Subject: How to fork from within .forward? Message-ID: <20021018135808.A2489@ns.museum.rain.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG I'm trying to set up an email-daemon which accepts info via email, acts on it, and returns a result. I have a dummy user set with a .forward file: "|./sample.sh $PPID" sample.sh parses the email text and creates a shell script. I'm new at this sort of thing, so my first uncertainty is the run-time environment of sample.sh. From looking at the output of "set >foo" from within sample.sh, I see variables like AGENT=sendmail etc., but otherwise a rather sparse environment. But nonetheless, sample.sh works and does its thing quickly. The shell script that sample.sh creates (child.sh) now needs to run. I want to run it under the userid to which the email was sent (the owner of the .forward file, duh). And in the background, so that the sendmail delivery process can complete and terminate. After some googling, man paging and trial and error (a 1:1 ratio in fact, of trial vs. error!) I have not been able to divine the proper command line to spawn a full-featured shell (one with valid PATH and HOME variables, etc.) which will allow the background script to execute. Unsuccessfull candidates have been: /usr/bin/su username -c ". child.sh" & and with 700 perms on child.sh I tried: /bin/sh ./child.sh & and /bin/sh - ./child.sh & without any luck. I also tried putting ". /etc/profile" near the top of child.sh. child.sh runs fine when I log in as username and run it manually via "./child.sh &". How can I spawn it from within the .forward file delivery process (sample.sh) that will spawn it in such a way that it inherits a login-style environment? To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message