Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 01 Oct 2008 16:48:35 -0400
From:      Lowell Gilbert <freebsd-questions-local@be-well.ilk.org>
To:        Steve Bertrand <steve@ibctech.ca>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Using global environment variables inside a subshell
Message-ID:  <44hc7wqbx8.fsf@be-well.ilk.org>
In-Reply-To: <48E380C4.4090304@ibctech.ca> (Steve Bertrand's message of "Wed\, 01 Oct 2008 09\:53\:08 -0400")
References:  <48E380C4.4090304@ibctech.ca>

next in thread | previous in thread | raw e-mail | index | archive | help
Steve Bertrand <steve@ibctech.ca> 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/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?44hc7wqbx8.fsf>