Shell 将标准输出重定向到文件并添加时间戳
我发现此脚本()用于重定向脚本/程序的stdout/stderr并添加时间戳:Shell 将标准输出重定向到文件并添加时间戳,shell,scripting,Shell,Scripting,我发现此脚本()用于重定向脚本/程序的stdout/stderr并添加时间戳: #!/bin/bash while read line ; do echo "$(date): ${line}" done 使用此脚本(predate.sh)时,如 它工作得很好,但是当MyApp崩溃或被杀死时,predate.sh脚本会持续运行,并且不会终止。有人知道如何解决这个问题吗 可能存在缓冲问题。我认为这会对你有用: producer | stdbuf -oL gawk '{print strft
#!/bin/bash
while read line ; do
echo "$(date): ${line}"
done
使用此脚本(predate.sh)时,如
它工作得很好,但是当MyApp崩溃或被杀死时,predate.sh脚本会持续运行,并且不会终止。有人知道如何解决这个问题吗 可能存在缓冲问题。我认为这会对你有用:
producer | stdbuf -oL gawk '{print strftime("%F %T"), $0}' > out.log
为您的
读取添加超时,如果超时,请检查MyApp是否正在运行,如果没有,请退出,如果正在运行,请重新读取
read -t 1 line
if [ $? -eq 1 ]; then
# Timeout - check MyApp ruuning
ps ... | grep MyApp ...
fi
谢谢,不幸的是,我正在使用嵌入式设备,stdbuf不可用
read -t 1 line
if [ $? -eq 1 ]; then
# Timeout - check MyApp ruuning
ps ... | grep MyApp ...
fi