Last active
July 8, 2020 10:29
-
-
Save zqigolden/6c23fbc4a791beb796e196caa05a9ffe to your computer and use it in GitHub Desktop.
[hdfs] classical hdfs, save to ~/bin/hdfs and chmod +x ~/bin/hdfs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#set -x | |
##can set user here | |
#USER=qzhu | |
which hdfscli &> /dev/null | |
test $? == 0 || pip3 install aibee_hdfs -I -i http://repo.aibee.cn/repository/pypi/simple --trusted-host repo.aibee.cn | |
test -f ~/${USER}.keytab || (cd ~ && create_keytab $USER) | |
hdfscli initkrb5 -k ~/${USER}.keytab ${USER} | |
IDC=${IDC-bj} | |
if [[ "$1" == dfs ]]; then | |
shift | |
fi | |
cmd=$1 | |
if [[ "$cmd" == -ls || "$cmd" == ls || "$cmd" == l ]]; then | |
cmd=list | |
fi | |
if [[ "$cmd" == -put || "$cmd" == put || "$cmd" == p ]]; then | |
cmd=upload | |
fi | |
if [[ "$cmd" == -get || "$cmd" == get || "$cmd" == g ]]; then | |
cmd=download | |
fi | |
shift | |
dst='' | |
if [[ $# -eq 1 && "$cmd" == download ]]; then | |
dst=' .' | |
fi | |
if [[ $# -eq 1 && "$cmd" == upload ]]; then | |
dst=' /bj_dev/user/qzhu/upload_files' | |
fi | |
src='' | |
counter=1 | |
#echo $# | |
for i in $@; do | |
i=$( sed -E 's@hdfs://@@g' <<< $i ) | |
if [[ ( ( "$cmd" == download && $counter == 1 ) || "$cmd" == list ) && $i != "/bj"* && $i != "/sh"* && $i != "/gz"* && $i != "-"* ]];then | |
i=/${IDC}$i | |
fi | |
counter=$((counter + 1)) | |
src="$src $i" | |
done | |
hdfscli $cmd $src $dst | |
## For debug | |
#echo hdfscli $cmd $src $dst |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment