通过webhdfs put文件到hdfs

通过rest API的webhdfs走的http,不需要安装hadoop客户端了。

put代码如下:

#!/bin/sh
###################
. /etc/profile
. ~/.bash_profile
##################
echo =====================================`date`===============================================
SCRIPT_NAME=$(readlink -f "$0")
dir=`dirname ${SCRIPT_NAME}`
cd $dir
localFile=$1
echo $localFile
hdfsFile=$2
echo $hdfsFile
namenode=nn.tv.hadoop.sohuno.com
url=`curl -i -X PUT "http://$namenode:50070/webhdfs/v1${hdfsFile}?op=CREATE&user.name=rc&overwrite=true&replication=3" | grep Location | awk -F ' ' '{print $2}'`
curl -i -X PUT -T $localFile "$url"
if [[ $? -eq 0 ]];then
  exit 100
else
  exit 1
fi



你可能感兴趣的:(hadoop)