From owner-freebsd-questions@FreeBSD.ORG Wed Oct 1 20:48:37 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 23DF21065690 for ; Wed, 1 Oct 2008 20:48:37 +0000 (UTC) (envelope-from freebsd-questions-local@be-well.ilk.org) Received: from mail6.sea5.speakeasy.net (mail6.sea5.speakeasy.net [69.17.117.8]) by mx1.freebsd.org (Postfix) with ESMTP id F1BDD8FC14 for ; Wed, 1 Oct 2008 20:48:36 +0000 (UTC) (envelope-from freebsd-questions-local@be-well.ilk.org) Received: (qmail 15224 invoked from network); 1 Oct 2008 20:48:37 -0000 Received: from dsl092-078-145.bos1.dsl.speakeasy.net (HELO be-well.ilk.org) ([66.92.78.145]) (envelope-sender ) by mail6.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 1 Oct 2008 20:48:37 -0000 Received: by be-well.ilk.org (Postfix, from userid 1147) id 830C428457; Wed, 1 Oct 2008 16:48:35 -0400 (EDT) To: Steve Bertrand References: <48E380C4.4090304@ibctech.ca> From: Lowell Gilbert Date: Wed, 01 Oct 2008 16:48:35 -0400 In-Reply-To: <48E380C4.4090304@ibctech.ca> (Steve Bertrand's message of "Wed\, 01 Oct 2008 09\:53\:08 -0400") Message-ID: <44hc7wqbx8.fsf@be-well.ilk.org> User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: freebsd-questions@freebsd.org Subject: Re: Using global environment variables inside a subshell X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-questions@freebsd.org List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Oct 2008 20:48:37 -0000 Steve Bertrand writes: > I've fudged together a quick disk space monitor that I will run from > cron. Running the script works fine from the command line, but when I > run it from cron, the environment variable is empty. > > Can someone point out the err of my ways?: > > #!/bin/sh > > /bin/df | \ > /usr/bin/awk '{if($5 ~ "%" && $6 !~ "proc") {used=$5} else {used=""}; \ > sub(/%/, "", used); \ > if(used > 95) print $6 " is at " used"% on "ENVIRON["HOSTNAME"]"!"}' | \ > mail -s "Disk usage action required" email@addr.com The environment under which cron jobs are run is very spare. It's more or less limited to the variables that are listed in the crontab(5) manual. You need to get the value into your script another way. In this case, I would use hostname(1). -- Lowell Gilbert, embedded/networking software engineer, Boston area http://be-well.ilk.org/~lowell/