将hdfs命令输出存储到shell变量

时间:2016-08-22 17:13:04

标签: shell hdfs

我正在尝试将hdfs命令输出到shell变量但是收到错误。我的脚本如下:

id

谢谢, stacky

2 个答案:

答案 0 :(得分:0)

这是否有效 - 按原样复制并粘贴。

#!/bin/bash
default=$1
date=""
HDFS_PATH='/data/max_emp_value' #(This is a directory)
if $(hadoop fs -test -e $HDFS_PATH/*)
then
    date="`hadoop fs -cat $HDFS_PATH/*)`"
else
    date=$default
fi
echo "date is ${date}"

为什么要检查目录中的所有文件? $HDFS_PATH/* *引用目录中的所有文件。您可能正在尝试检查文件是否已到达 - 在这种情况下,您应该在传输完成后将一个触摸文件标记为_success。否则,您可能会在传输中消耗数据。

答案 1 :(得分:0)

您的脚本有一些语法错误(第6行:〜&gt;未经过验证的 #include <stdafx.h> // Visual Studio users need to uncomment this line #include <iostream> int nameAppears() { std::cout << "Alex" << std::endl; std::cout << "Andre" << std::endl; std::cout << "Guy" << std::endl; std::cout << "Grand-ma" << std::endl; std::cout << "Grand-pa" << std::endl; std::cout << "Jérémy" << std::endl; std::cout << "Manon" << std::endl; std::cout << "Nathalie" << std::endl; std::cout << "Stéphanie" << std::endl; std::cout << "Oliver" << std::endl; } int enterName() { std::cout << "Enter the name you wish to obtain the number:"; int name; std::cin >> name; return name; } int link(name) { if (name == "Alex") return "586 6532"; if (name == "Andre") return "569 8522"; if (name == "Guy") return "850 6589"; if (name == "Grand-ma") return "482 4875"; if (name == "Grand-pa") return "453 9963"; if (name == "Jérémy") return "654 3828"; if (name == "Manon") return "965 4541"; if (name == "Nathalie") return "770 6916"; if (name == "Stéphanie") return "546 5482 "; if (name == "Oliver") return "246 5554"; } int printNumber (int number) { std::cout << "The number is: " << number << std::endl; } int main() { //Make all the names appear nameAppears(); //Get User's input int name = enterName(); //Link Name to number int number = link(name); //Print the desired number printNumber(number); } )之间的空格)。另外,尝试使用不是DATE =命令的变量名(bash是bash命令):

date
#!/bin/bash
default=$1
DATE=''
HDFS_PATH='/user/cloudera/datefiles'

if $(hadoop fs -test -e ${HDFS_PATH}/*); then
    DATE=`hadoop fs -cat ${HDFS_PATH}/*`
else
    DATE=${default}
fi
echo ${DATE}