When I run a bash script manually, the output appends my log file in the color specified using tput. When I run the bash script as a cronjob, the output loses the color. Thanks.
Asked
Active
Viewed 1,535 times
2
-
2Can you show the relevant parts of the script? – Reinstate Monica Please Aug 26 '14 at 18:23
-
when I run echo $TERM I get xterm. How do I change crontab to use xterm with color? – Ralph Shinevar Aug 27 '14 at 14:14
2 Answers
4
Your cron
environment almost certainly is just not specifying a terminal type that supports colors and so tput
is not returning anything.
Compare:
$ echo $TERM
xterm-256color
$ printf %q\\n "$(tput setaf 5)"
$'\E[35m'
$ printf %q\\n "$(TERM=dumb tput setaf 5)"
''

Etan Reisner
- 77,877
- 8
- 106
- 148
-
when I run echo $TERM I get xterm. How do I change crontab to use xterm with color? – Ralph Shinevar Aug 27 '14 at 14:15
-
`export TERM=xterm` or whatever other value you want to set for it or use the `-T` flag to `tput` to tell it what terminfo entry to use. – Etan Reisner Aug 27 '14 at 14:24
-
I put TERM=xterm export TERM in the bash_profile file and the colors are working! Thanks. – Ralph Shinevar Aug 27 '14 at 16:33
0
I put TERM=xterm export TERM in the bash_profile file and the colors are working.

Ralph Shinevar
- 21
- 2