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

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 "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8bfef8eef9cbeef3eae6fbe7eea5e8e4e6">[email protected]</a>" -s "Daily Inventory Unit Test Results" <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="265355435466435e474b564a430845494b">[email protected]</a>

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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
else
    echo ugly
fi

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x