From owner-freebsd-questions@FreeBSD.ORG Mon Feb 23 00:51:07 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 B223210656C3 for ; Mon, 23 Feb 2009 00:51:07 +0000 (UTC) (envelope-from SRS0=EOsdpJ=62=shell.siscom.net=vogelke@siscom.net) Received: from lamorack.siscom.net (lamorack.siscom.net [209.251.2.116]) by mx1.freebsd.org (Postfix) with ESMTP id 73C818FC14 for ; Mon, 23 Feb 2009 00:51:07 +0000 (UTC) (envelope-from SRS0=EOsdpJ=62=shell.siscom.net=vogelke@siscom.net) Received: from shell.siscom.net ([209.251.2.80]) by lamorack.siscom.net with esmtp (Exim 4.62) (envelope-from ) id 1LbOEI-0002yW-BN for freebsd-questions@freebsd.org; Sun, 22 Feb 2009 18:59:26 -0500 Received: by shell.siscom.net (Postfix, from userid 2198) id 2206F115529; Sun, 22 Feb 2009 18:59:26 -0500 (EST) Received: by kev.msw.wpafb.af.mil (Postfix, from userid 32768) id 6A657B7B8; Sun, 22 Feb 2009 18:58:44 -0500 (EST) To: freebsd-questions@freebsd.org In-reply-to: <499C2F76.30507@infracaninophile.co.uk> (message from Matthew Seaman on Wed, 18 Feb 2009 15:55:34 +0000) 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: <20090222235844.6A657B7B8@kev.msw.wpafb.af.mil> Date: Sun, 22 Feb 2009 18:58:44 -0500 (EST) From: vogelke+unix@pobox.com (Karl Vogel) Subject: Re: Problem with BASH and [ ! -t 0 ] test. 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: Mon, 23 Feb 2009 00:51:08 -0000 >> 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