2016-02-26 84 views
1

我想檢查文件是否存在於hdfs中。我使用檢查文件是否存在於帶有通配符的hdfs中

if $(hadoop fs -test -e $myfilewithpath) ; then echo "ok";else echo "not ok"; fi

現在我越來越喜歡

test: `/data/bi/udm/incoming/Viewership/year=2016/month=02/day=26/hour=07/part-m-*.avro': No such file or directory 
 
not ok

該文件的錯誤消息,我的路我希望可以是任何映射器輸出文件即它可以是part-m-00000.avro或者它可以是part-m-00099.avro這就是爲什麼我在我的搜索part-m-*.avro中使用*

但我們可以消除下面的消息,並得到唯一的輸出not ok

test: `/data/bi/udm/incoming/Viewership/year=2016/month=02/day=26/hour=07/part-m-*.avro': No such file or directory

回答

1

我可以通過下面的代碼

if $(hadoop fs -ls $tilldirectorypath|grep "part-m-*.avro") ; then echo "ok";else echo "not ok"; fi

解決它

Where tilldirectorypath=/data/bi/udm/incoming/Viewership/year=2016/month=02/day=26/hour=07 
 

 
And previous path defined as myfilewithpath=/data/bi/udm/incoming/Viewership/year=2016/month=02/day=26/hour=07/part-m-*.avro

相關問題