linux - 如何在 HDFS 中存储 shell 脚本的日志文件

标签 linux shell hadoop hdfs

我在 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 中的文件不起作用。

使用-appendToFile

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/

相关文章:

linux - Iptables:两个 IP 地址,只允许一个端口 3306

linux - 将 Bash 脚本转换为 Shell

hadoop序列文件集合

shell - rand() 如何在 awk 中工作

MySQL 从 CSV 数据文件批量插入

java - 用另一个方法替换作业类中的方法 waitForCompletion()

hadoop - 控制 Spark 集群中作业或任务的分布

c - gdb 远程调试。实现一个伪造的 gdbserver stub 。经过多次请求和响应,得到警告 :invalid remote reply

linux - 如何在 bash 脚本中为命令输出着色?

linux - 保留通过 "less"或 "more"传输的文本的颜色