I am trying to run a bash script I have via cron, and I am getting the following error at the beginning of the execution:

tput: No value for $TERM and no -T specified

Here is what is in my crontab:

0 8 * * 1-5 cd /var/www/inv/ && /var/www/inv/unitTest run all 2>&1| mail -r "user@example.com" -s "Daily Inventory Unit Test Results" user@example.com

Your unit test script probably calls tput in order to generate pretty output showing which tests pass and fail. Under cron there is no terminal and thus no terminal type ($TERM), so tput cannot control the nonexistent terminal.

Your unit test script needs to have 2 modes:

  • running on a terminal: it can call tput to generate pretty-looking output
  • not running on a terminal: it should not call tput and instead generate a generic text-only output format that is suitable for piping into an email as you are doing here.

The easiest way for the unit tests to know whether or not they are running on a terminal is to test of the stdio file descritors refer to a terminal. If it's a shell script, then:

if [ -t 1 ]; then
    tput bold; echo pretty; tput sgr0
    echo ugly

Basically: do not call tput unless you are running on a terminal, and you will thus avoid the error you are getting, plus produce reasonable output in whichever mode you happen to be running under.

  • Realized I had this in my script sep=$(printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =). I guess this is where the tput issue is coming from. Thanks for the information, I'll try and apply it. – ComputerLocus Jun 11 '15 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.