问题
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.
回答1:
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)"
''
回答2:
I put TERM=xterm export TERM in the bash_profile file and the colors are working.
来源:https://stackoverflow.com/questions/25512588/how-do-i-get-colored-output-to-a-file-from-a-bash-script-running-in-crontab