shell腳本--linux終端運行hadoop--java文件
假設保存為test.sh,java文件為wc.java,【注:會打包成1.jar】,main函數所在類為wc,hdfs上輸入目錄地址為input,hdfs上輸出目錄地址為output【注:輸入目錄和輸出目錄非必須】 www.2cto.com
運行:
./test.sh wc.java wc input output
[plain]
#!/bin/bash
#echo "$# $0 $1 $2"
HH=$HADOOP_HOME
if [ $# -lt 2 ];then
echo "usage: jc.sh source.java ClassName [InputFile] [OutputFile]"
exit 0
elif [ ${1##*.} != "java" ];then
echo "Notice: source.java java!"
exit 0
else
rm -r ./classes/*
javac -classpath $HH/hadoop-mapred-0.22.0.jar:$HH/hadoop-hdfs-0.22.0.jar:$HH/hadoop-common-0.22.0.jar:$HH/lib/commons-cli-1.2.jar -d classes ./$1
jar -cvf 1.jar -C classes/ .
echo "==============Output====================="
if [ $# -eq 2 ];then
hadoop jar 1.jar $2
elif [ $# -eq 3 ];then
hadoop jar 1.jar $2 $3
elif [ $# -eq 4 ];then
hadoop jar 1.jar $2 $3 $4
fi
echo "========================================="
rm 1.jar
fi