From owner-freebsd-questions@FreeBSD.ORG Wed Feb 18 20:09:48 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 814E6106564A for ; Wed, 18 Feb 2009 20:09:48 +0000 (UTC) (envelope-from fbsd.questions@rachie.is-a-geek.net) Received: from mail.rachie.is-a-geek.net (rachie.is-a-geek.net [66.230.99.27]) by mx1.freebsd.org (Postfix) with ESMTP id 4F4388FC0A for ; Wed, 18 Feb 2009 20:09:47 +0000 (UTC) (envelope-from fbsd.questions@rachie.is-a-geek.net) Received: from localhost (mail.lan.rachie.is-a-geek.net [192.168.2.101]) by mail.rachie.is-a-geek.net (Postfix) with ESMTP id 5E30DAFC1FE; Wed, 18 Feb 2009 11:09:47 -0900 (AKST) From: Mel To: freebsd-questions@freebsd.org Date: Wed, 18 Feb 2009 11:09:47 -0900 User-Agent: KMail/1.9.10 References: <502804.7096.qm@web32108.mail.mud.yahoo.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-6" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200902181109.47179.fbsd.questions@rachie.is-a-geek.net> Cc: Subject: Re: Problem with BASH and [ ! -t 0 ] test. X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Feb 2009 20:09:48 -0000 On Wednesday 18 February 2009 10:40:47 Warren Block wrote: > On Wed, 18 Feb 2009, GESBBB wrote: > > I am using this snippet of code in a bash script that is run via CRON. > > =A0 > > > > # See if we are running via CRON > > =A0=A0=A0 if [ ! -t 0 ] > > =A0=A0=A0=A0=A0 then > > # Use the BASH RANDOM function to generate a random number between 0 & > > 32767 RESTING=3D$((RANDOM/60)) > > =A0=A0=A0=A0=A0=A0=A0 sleep ${RESTING} > > =A0=A0=A0 fi > > > > =A0 > > =A0 > > It runs fine from the console; however, when run via CRON, it outputs > > this error message.=20 > > Tput: No terminal type specified and no TERM environmental variable. > > =A0 > > I have Googled about, yet I cannot find an answer. Perhaps some Bash gu= ru > > can assist me. > > cron uses /bin/sh, not bash. No. cron uses execvp, which will: 1) execute as binary if header is recognized 2) execute with whatever the she-bang says (#!) 3) run as /bin/sh /path/to/file if 1) and 2) fail. Can't reproduce the error though, using: #!/usr/local/bin/bash unset TERM sleep 1; if [ ! -t 0 ]; then echo No term >> out else echo term >> out fi I run as: daemon ./test.sh 2>err then logout the ssh session, so terminal becomes invalid. It correctly says= =20 term and no term, no tput errors. Same for /bin/sh, by the way. =2D-=20 Mel Problem with today's modular software: they start with the modules and never get to the software part.