我有这段代码:
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/