Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Feb 2009 18:58:44 -0500 (EST)
From:      vogelke+unix@pobox.com (Karl Vogel)
To:        freebsd-questions@freebsd.org
Subject:   Re: Problem with BASH and [ ! -t 0 ] test.
Message-ID:  <20090222235844.6A657B7B8@kev.msw.wpafb.af.mil>
In-Reply-To: <499C2F76.30507@infracaninophile.co.uk> (message from Matthew Seaman on Wed, 18 Feb 2009 15:55:34 %2B0000)

next in thread | previous in thread | raw e-mail | index | archive | help
>> In a previous message, gesbbb@yahoo.com wrote:

G> I am using this snippet of code in a bash script that is run via CRON.
G> 
G>   # See if we are running via CRON
G>   if [ ! -t 0 ] ...
G> 
G> It runs fine from the console; however, when run via CRON, it outputs Tput:
G> No terminal type specified and no TERM environmental variable.

   On FreeBSD, I set an environment variable in the crontab file so I
   can check if something's being run via cron.  This has the advantage
   of not depending on any scripting language.  A sample crontab's below
   the signature.

   You can also set TERM to something harmless (say, vt100) but if
   something else is really expecting interactive behavior, that might
   come back to haunt you.  The safest bet is to find out what's expecting
   TERM to be set and either wrap it...

     case "$CRON" in
         "") interactive code here ;;
        yes) ;;
     esac

   ...or get rid of it.

-- 
Karl Vogel                      I don't speak for the USAF or my company
Man who live in glass house, dress in basement.         --Bryan Albright

---------------------------------------------------------------------------
# Everything on a line is separated by blanks or tabs.
#
#+--------------------------- Minute (0-59)
#|   +----------------------- Hour   (0-23)
#|   |     +----------------- Day    (1-31)
#|   |     |   +------------- Month  (1-12)
#|   |     |   |   +--------- Day of week (0-6, 0=Sunday)
#|   |     |   |   |    +---- Command to be run
#|   |     |   |   |    |
#v   v     v   v   v    v
#========================================================================
# Shell variables
CRON=yes
#========================================================================
# Keep an eye on disk space.
4    *     *   *   *    /usr/local/cron/checkdrives
# Store browser history.
59  23     *   *   *    $HOME/cron/mozhist



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