分享個自己的hadoop 執行的shell指令碼,
不過對於會寫shell指令碼的人估計用不到,
對於不會寫shell指令碼的人似乎又看不懂。
如果有興趣學習的話可以私下聯絡。至於
指令碼中涉及的相關檔案(源碼/compile.sh),未能上傳。
權且做個記錄,方便自己後期回顧而已。
由於僅供自己測試用,所以比較粗糙
執行時:
直接執行程式
hadoop@namenode#./HadoopRunAveragePower
重新編譯執行
hadoop@namenode#./HadoopRunAveragePower y 指令檔如下:
#!/bin/sh
#HadoopRunAveragePower isStandalone=0 #isStandalone : 0 hadoop clust ; 1 Standalone
COMPILEFILE="averagepowercompile.sh"
SOURCEFOLDER="workspace/averagePower/"
JARFOLDER="."
INPUTPATH="input2/"
OUTPUTPATH="output/"
JARFILE="averagepower.jar"
JARMAINCLASS="workdir.AveragePower"
COMPRESSORNOT="true"
MAPTASKNUM=2
REDUCETASKNUM=1
isRebuild="n"
if [ "$#" -gt 0 ];then
#echo Do you want to run rebuild this application[Y/N]?
echo "Ready To Rebuild Source"
if [ "$1"="y" ];then
isRebuild=$1
elif [ "$1"="Y" ];then
isRebuild=$1
fi
case "$isRebuild" in
[Yy]*)
echo do:find $SOURCEFOLDER -name *.java~ -exec rm -f {} \;
find $SOURCEFOLDER -name *.java~ -exec rm -f {} \;
echo do:find $SOURCEFOLDER -name *.class -exec rm -f {} \;
find $SOURCEFOLDER -name *.class -exec rm -f {} \;
echo do:rm -vf $JARFILE
rm -vf $JARFILE
echo do:bash $COMPILEFILE
bash $COMPILEFILE
echo do:jar -cvf $JARFILE -C $SOURCEFOLDER $JARFOLDER
jar -cvf $JARFILE -C $SOURCEFOLDER $JARFOLDER
echo "Rebuild Application Successfully"
;;
*)
echo "Parameter Error"
echo "Not Rebuild Application "
exit;;
esac
else
echo "Not Rebuild Application "
fi
echo Do you want to run this application[Y/N]?
read answer
case "$answer" in
[Yy]*)
if [ "$isStandalone" -eq 0 ];then
echo do: bin/hadoop fs -rmr $OUTPUTPATH
bin/hadoop fs -rmr $OUTPUTPATH
else
echo do: rm -rvf $OUTPUTPATH
rm -rvf $OUTPUTPATH
fi
echo do:bin/hadoop jar $JARFILE $JARMAINCLASS -c $COMPRESSORNOT -m $MAPTASKNUM -r $REDUCETASKNUM $INPUTPATH $OUTPUTPATH
bin/hadoop jar $JARFILE $JARMAINCLASS -c $COMPRESSORNOT -m $MAPTASKNUM -r $REDUCETASKNUM $INPUTPATH $OUTPUTPATH
echo input_dir: $INPUTPATH
echo input_dir: $OUTPUTPATH
echo Application Success Done and Exited.
;;
*) exit;;
esac