hadoop - curl 下载到 HDFS

标签 hadoop curl hdfs

我有这段代码:

curl -o fileName.csv url | xargs hdfs dfs -moveFromLocal $1 /somePath/

当我执行此代码时,curl 将请求中的值放入 fileName.csv 中,文件将移动到 HDFS。我想知道我是否可以在内存中保留 curl 输出,发送到管道,然后将值写入 HDFS?

像这样的东西(有效):

curl url | xargs hdfs dfs -put $1 /somePath

最佳答案

hdfs dfs -put 命令可以接受来自 stdin 的文件输入,使用熟悉的习惯用法指定 - 表示 stdin:

> curl -sS https://www.google.com/robots.txt | hdfs dfs -put - /robots.txt
> hdfs dfs -ls /robots.txt
-rw-r--r--   3 cnauroth supergroup       6880 2017-07-06 09:07 /robots.txt

另一种选择是使用 shell process substitution允许将 curl(或您选择的任何命令)的标准输出视为另一个命令的文件输入:

> hdfs dfs -put <(curl -sS https://www.google.com/robots.txt) /robots.txt
> hdfs dfs -ls /robots.txt
-rw-r--r--   3 cnauroth supergroup       6880 2017-07-05 15:07 /robots.txt

关于hadoop - curl 下载到 HDFS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44936241/

相关文章:

将文件移动到 hadoop 集群的 Shell 脚本

java - Hadoop Map/Reduce Mapper 'map'方法和日志

apache-spark - 如何将 HDFS(Hadoop 分布式文件系统)部署到 K8s(Kubernetes)集群?

hadoop - 使用 globStatus 和 Google Cloud Storage 存储桶作为输入时无法运行 Spark 作业

php - 未捕获的 CurlException : 28: SSL connection timeout - Facebook PHP SDK

javascript - 无法从 http post 方法获取 req.body 属性

c++ - 使用 cURL 在 C++ 中将网页保存到内存

hadoop - 如何为 Sqoop 输出文件指定自定义名称

hadoop - Apache Nifi 无法写入 HDFS

java - 在 Hadoop 中映射和减少类属性