Date: Wed, 18 Feb 2009 11:09:47 -0900 From: Mel <fbsd.questions@rachie.is-a-geek.net> To: freebsd-questions@freebsd.org Subject: Re: Problem with BASH and [ ! -t 0 ] test. Message-ID: <200902181109.47179.fbsd.questions@rachie.is-a-geek.net> In-Reply-To: <alpine.BSF.2.00.0902181238280.15654@wonkity.com> References: <502804.7096.qm@web32108.mail.mud.yahoo.com> <alpine.BSF.2.00.0902181238280.15654@wonkity.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 > > <snippet> > > # 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 > > </snippet> > > =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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200902181109.47179.fbsd.questions>