我如何获得在crontab中运行bash脚本的彩色输出到文件? [英] How do I get colored output to a file from a bash script running in crontab?
本文介绍了我如何获得在crontab中运行bash脚本的彩色输出到文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我手动运行bash脚本,输出附加在颜色我的日志文件使用指定的输出。当我运行bash脚本作为一个cronjob,输出失去颜色。谢谢。
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.
推荐答案
您的cron
环境几乎可以肯定是不指定支持色彩的终端类型等 tput的
不返回任何东西。
Your cron
environment almost certainly is just not specifying a terminal type that supports colors and so tput
is not returning anything.
比较:
$ echo $TERM
xterm-256color
$ printf %q\\n "$(tput setaf 5)"
$'\E[35m'
$ printf %q\\n "$(TERM=dumb tput setaf 5)"
''
这篇关于我如何获得在crontab中运行bash脚本的彩色输出到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文