[英]How to store log files of a shell script in HDFS
I have shell script in HDFS
. 我在
HDFS
有shell脚本。 I want to collect the logs for this script in HDFS only. 我只想在HDFS中收集此脚本的日志。
The contents of the script are below: 该脚本的内容如下:
#!/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
}
The logs are not appending to the files. 日志未追加到文件。 only the files are being created.
仅创建文件。
How can I get the files to have the result of the function to be appended in HDFS
如何获取文件以将功能结果附加到
HDFS
The logs are not appending to the files.
日志未追加到文件。 only the files are being created.
仅创建文件。
Because tee
is a linux command and does not work for files stored in HDFS. 因为
tee
是linux命令,不适用于HDFS中存储的文件。
Use -appendToFile
使用
-appendToFile
echo "`date +\"%Y-%m-%d %H:%M:%S\"` [ERROR] $message [Status] $status : failed" | hdfs dfs -appendToFile - ${failed_logs}
-
in place of srcfile
is to read the input from stdin. -
代替srcfile
是从stdin读取输入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.