我在 HDFS
中有 shell 脚本。我只想在 HDFS 中收集此脚本的日志。
脚本内容如下:
#!/bin/bash
TIMESTAMP=`date "+%Y-%m-%d"`
hdfs dfs -touchz /user/$USER/logs/`date "+%Y-%m-%d"`/${TIMESTAMP}.success_log
hdfs dfs -touchz /user/$USER/logs/`date "+%Y-%m-%d"`/${TIMESTAMP}.fail_log
success_logs=/user/$USER/logs/`date "+%Y-%m-%d"`/${TIMESTAMP}.success_log
failed_logs=/user/$USER/logs/`date "+%Y-%m-%d"`/${TIMESTAMP}.fail_log
function log_status
{
status=$1
message=$2
if [ "$status" -ne 0 ]; then
echo "`date +\"%Y-%m-%d %H:%M:%S\"` [ERROR] $message [Status] $status : failed" | tee -a "${failed_logs}"
#echo "Please find the attached log file for more details"
exit 1
else
echo "`date +\"%Y-%m-%d %H:%M:%S\"` [INFO] $message [Status] $status : success" | tee -a "${success_logs}"
fi
}
日志没有附加到文件中。仅创建文件。
如何让文件具有要附加到 HDFS
中的函数的结果
最佳答案
The logs are not appending to the files. only the files are being created.
因为 tee
是一个 linux 命令,对存储在 HDFS 中的文件不起作用。
echo "`date +\"%Y-%m-%d %H:%M:%S\"` [ERROR] $message [Status] $status : failed" | hdfs dfs -appendToFile - ${failed_logs}
-
代替 srcfile
是从 stdin 读取输入。
关于linux - 如何在 HDFS 中存储 shell 脚本的日志文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43332545/