我正在尝试回显错误消息并同时将其写入日志文件,但我不确定该怎么做。我已经使用了 1>&2,但它只是将它发送到日志文件并且不回显消息。这是我的代码:
while read -r username password; do
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "ERROR BLABLAH $DATE" 1>&2 >> /var/log/error.log
最佳答案
尝试
echo "ERROR BLABLAH $DATE" | tee -a /var/log/error.log 1>&2
描述:
tee # will repeat the std input.
-a /var/log/error.log # will append to the error.log file
1>&2 # will send the stdin to stderr.
关于linux - 我可以回显错误消息并将其发送到日志文件中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39731908/