Re: Problem with BASH and [ ! -t 0 ] test.
In a previous message, ges...@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 vv # # Shell variables CRON=yes # # Keep an eye on disk space. 4* * * */usr/local/cron/checkdrives # Store browser history. 59 23 * * *$HOME/cron/mozhist ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Problem with BASH and [ ! -t 0 ] test.
I am using this snippet of code in a bash script that is run via CRON. snippet # See if we are running via CRON if [ ! -t 0 ] then # Use the BASH RANDOM function to generate a random number between 0 32767 RESTING=$((RANDOM/60)) sleep ${RESTING} fi /snippet It runs fine from the console; however, when run via CRON, it outputs this error message. Tput: No terminal type specified and no TERM environmental variable. I have Googled about, yet I cannot find an answer. Perhaps some Bash guru can assist me. -- Gerard ges...@yahoo.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Problem with BASH and [ ! -t 0 ] test.
-BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 GESBBB wrote: | I am using this snippet of code in a bash script that is run via CRON. | | | snippet | # See if we are running via CRON | if [ ! -t 0 ] | then | # Use the BASH RANDOM function to generate a random number between 0 32767 | RESTING=$((RANDOM/60)) | sleep ${RESTING} | fi | /snippet | | | It runs fine from the console; however, when run via CRON, it outputs this error message. | | Tput: No terminal type specified and no TERM environmental variable. | | I have Googled about, yet I cannot find an answer. Perhaps some Bash guru can assist me. | jot -r 1 0 546 Cheers, Matthew - -- Dr Matthew J Seaman MA, D.Phil. Flat 3 ~ 7 Priory Courtyard PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate ~ Kent, CT11 9PW, UK -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.10 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEAREDAAYFAkmcL3YACgkQ8Mjk52CukIxn9ACePfwIwfNo1q1Sp6zPm9zDB4fh uhcAnjskxg142o6FeMRNLJwrIMZwJFGi =VPTj -END PGP SIGNATURE- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Problem with BASH and [ ! -t 0 ] test.
On Wed, 18 Feb 2009, GESBBB wrote: I am using this snippet of code in a bash script that is run via CRON. snippet # See if we are running via CRON if [ ! -t 0 ] then # Use the BASH RANDOM function to generate a random number between 0 32767 RESTING=$((RANDOM/60)) sleep ${RESTING} fi /snippet It runs fine from the console; however, when run via CRON, it outputs this error message. Tput: No terminal type specified and no TERM environmental variable. I have Googled about, yet I cannot find an answer. Perhaps some Bash guru can assist me. cron uses /bin/sh, not bash. -Warren Block * Rapid City, South Dakota USA___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Problem with BASH and [ ! -t 0 ] test.
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. snippet # See if we are running via CRON if [ ! -t 0 ] then # Use the BASH RANDOM function to generate a random number between 0 32767 RESTING=$((RANDOM/60)) sleep ${RESTING} fi /snippet It runs fine from the console; however, when run via CRON, it outputs this error message. Tput: No terminal type specified and no TERM environmental variable. I have Googled about, yet I cannot find an answer. Perhaps some Bash guru 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 2err then logout the ssh session, so terminal becomes invalid. It correctly says term and no term, no tput errors. Same for /bin/sh, by the way. -- Mel Problem with today's modular software: they start with the modules and never get to the software part. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Problem with BASH and [ ! -t 0 ] test.
From: Matthew Seaman m.sea...@infracaninophile.co.uk GESBBB wrote: | I am using this snippet of code in a bash script that is run via CRON. | | | | # See if we are running via CRON | if [ ! -t 0 ] | then | # Use the BASH RANDOM function to generate a random number between 0 32767 | RESTING=$((RANDOM/60)) | sleep ${RESTING} | fi | | | | It runs fine from the console; however, when run via CRON, it outputs this error message. | | Tput: No terminal type specified and no TERM environmental variable. | | I have Googled about, yet I cannot find an answer. Perhaps some Bash guru can assist me. | jot -r 1 0 546 Cheers, Matthew I am a little confused. I believe the problem is with the if [ ! -t 0 ] statement. I tried to redirect the error message; however, it still appears in the email sent by CRON. I tried using this statement instead: if ( ! tty -s /dev/null ) and if ( ! tty -s ) /dev/null; however, they also produce an error message although the function does work correctly. Is this just something I should just ignore, or is there a way to stop the message from being sent in the CRON report? -- Gerard ges...@yahoo.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Problem with BASH and [ ! -t 0 ] test.
On Feb 18, 2009, at 12:29 PM, GESBBB wrote: I am a little confused. I believe the problem is with the if [ ! -t 0 ] statement. I tried to redirect the error message; however, it still appears in the email sent by CRON. I tried using this statement instead: if ( ! tty -s /dev/null ) and if ( ! tty -s ) /dev/null; however, they also produce an error message although the function does work correctly. Is this just something I should just ignore, or is there a way to stop the message from being sent in the CRON report? For Bourne shell, classic /bin/sh, and related shells (zsh, ksh), you can use something like: case $- in *i*) # do stuff for an interactive shell echo interactive ;; *) # not interactive echo not interactive ;; esac Regards, -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Problem with BASH and [ ! -t 0 ] test.
On Wed, Feb 18, 2009 at 07:18:03AM -0800, GESBBB wrote: I am using this snippet of code in a bash script that is run via CRON. ? ? snippet # See if we are running via CRON ??? if [ ! -t 0 ] ? then # Use the BASH RANDOM function to generate a random number between 0 32767 ??? RESTING=$((RANDOM/60)) ??? sleep ${RESTING} ??? fi /snippet ? ? It runs fine from the console; however, when run via CRON, it outputs this error message. ? Tput: No terminal type specified and no TERM environmental variable. Bash is looking up the user's bash startup-scripts, and one of the script commands assumes that it's running on a terminal. -- Jonathan Chen j...@chen.org.nz -- In mathematics you don't understand things. You just get used to them. - Johann von Neumann ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org