代码语言:shell复制
#!/bin/bash
workdir=$(cd $(dirname $0); pwd)
date=`date %Y-%m-%d-%H:%M:%S`
init(){
rm -rf $workdir/hdfs_detail.txt
touch $workdir/hdfs_detail.txt
chmod 777 $workdir/hdfs_detail.txt
echo "[Init Time]:$date" >> $workdir/hdfs_detail.txt
echo "--" >> $workdir/hdfs_detail.txt
echo "--" >> $workdir/hdfs_detail.txt
}
hdfs_collect(){
echo " ----[ 汇总数据 ]---- " >> $workdir/hdfs_detail.txt
echo "" >> $workdir/hdfs_detail.txt
echo "| 总量 | 当前目录 |" >> $workdir/hdfs_detail.txt
hadoop fs -du / |sort -r -n| awk '{size=$1/1024;if(size<1024){printf(".3f KBt%sn",size,$2);}else{size=size/1024;if(size<1024){printf("