From owner-freebsd-questions@FreeBSD.ORG Fri Jun 5 22:49:09 2009 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 CCD7310656A6 for ; Fri, 5 Jun 2009 22:49:09 +0000 (UTC) (envelope-from vogelke@hcst.com) Received: from beta.hcst.com (beta.hcst.com [192.52.183.241]) by mx1.freebsd.org (Postfix) with ESMTP id 73B1E8FC29 for ; Fri, 5 Jun 2009 22:49:09 +0000 (UTC) (envelope-from vogelke@hcst.com) Received: from beta.hcst.com (localhost [127.0.0.1]) by beta.hcst.com (8.13.8/8.13.8/Debian-3) with ESMTP id n55Mn6wH018238 for ; Fri, 5 Jun 2009 18:49:06 -0400 Received: (from vogelke@localhost) by beta.hcst.com (8.13.8/8.13.8/Submit) id n55Mn6qd018237; Fri, 5 Jun 2009 18:49:06 -0400 Received: by kev.msw.wpafb.af.mil (Postfix, from userid 32768) id 18F65BED2; Fri, 5 Jun 2009 18:48:28 -0400 (EDT) To: freebsd-questions@freebsd.org In-reply-to: <20090605190200.GH87456@kokopelli.hydra> (message from Chad Perrin on Fri, 5 Jun 2009 13:02:00 -0600) Organization: Oasis Systems Inc. X-Disclaimer: I don't speak for the USAF or Oasis. X-GPG-ID: 1024D/711752A0 2006-06-27 Karl Vogel X-GPG-Fingerprint: 56EB 6DBF 4224 C953 F417 CC99 4C7C 7D46 7117 52A0 Message-Id: <20090605224828.18F65BED2@kev.msw.wpafb.af.mil> Date: Fri, 5 Jun 2009 18:48:28 -0400 (EDT) From: vogelke+unix@pobox.com (Karl Vogel) Subject: Re: Can a Bourn Shell Script put itself in the background? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: vogelke+unix@pobox.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jun 2009 22:49:10 -0000 >> On Fri, 5 Jun 2009 13:02:00 -0600, >> Chad Perrin said: C> I got the impression this question was about a script backgrounding itself, C> though -- possibly creating a daemon using bash. Same here. This seems a bit slimy, but it works (assuming you don't already have an environment variable called DAEMON): me% cat doit #!/bin/ksh # script to daemonize itself. PATH=/usr/local/bin:/bin:/usr/bin:/usr/sbin; export PATH umask 022 env | grep 'DAEMON=yes' > /dev/null case $? in 0) logger -t test "$$ is a daemon, args $@" ;; 1) echo "$$ not a daemon, args $@" DAEMON=yes daemon $0 ${1+"$@"} ;; esac exit 0 me% ./doit a b c 18131 not a daemon, args a b c me% tail -1 /var/log/syslog Jun 5 18:41:54 host test: 18135 is a daemon, args a b c -- Karl Vogel I don't speak for the USAF or my company Gingko Viagra: to help you remember what the f*** you're doing.