Shell 检查HDfS文件

news/2024/5/20 1:30:32 标签: shell, hdfs, 是否存在, 文件大小

平常脚本运行需要检查对应hdfs路径相关信息,总结一下:

Tip: 假设要检查的路径为check_path

1.获取路径文件大小并转化为规定单位 Byte,K,M,G

bytes获取文件大小,单位为字节;base为转换单位的基准,我这里取1G,所以是1x1024x1024x1024bytes,其他单位转换同理;第三步real只需要做除法即可,bc是shell自带运算处理,这里做2位小数保留,其余同理

#获取大小
bytes=`hadoop fs -du -s $check_path|awk -F " " '{print $1}'`
base=1073741824
real=`echo "scale=2; $bytes/$base" | bc`

2.检查文件是否存在

#检查路径是否存在
function check_exist(){
hadoop fs -test -e $check_path
if [ $? -eq 0 ] ;then
    echo 'path exist'
else
    echo 'Error! path is not exist'
fi
}
check_exist

3.检查是否为文件夹

#检测路径是否为文件夹
function check_isDir(){
hadoop fs -test -d $check_path
if [ $? -eq 0 ] ;then
    echo 'Is a directory'
else
    echo 'Is not a directory'
fi
}

4.检查是否为文件

#检测路径是否为📃
function check_isFile(){
hadoop fs -test -f $check_path
if [ $? -eq 0 ] ;then
    echo 'Is a file'
else
    echo 'Is not a file'
fi
}

5.检查文件是否超过指定大小

#检测📃大小是否超过超过阈值 默认byte
function check_Capacity(){
capacity=$1
hadoop fs -test -s $check_path
if [ $? -eq $capacity ] ;then
    echo "超过"${capacity} " bytes/100 M"
else
    echo "未超过"${capacity} " bytes/100 M"
fi
}

6.检查文件是否为空

#检测📃大小是否为空
function check_Empty(){
hadoop fs -test -z $check_path
if [ $? -eq 0 ] ;then
    echo 'Is zero bytes in size.'
else
    echo 'Is not zero bytes in size. '
fi
}

以上直接使用即可


http://www.niftyadmin.cn/n/1236146.html

相关文章

面试官:给我讲讲SpringBoot的依赖管理和自动配置?

1、前言 从Spring转到SpringBoot的xdm应该都有这个感受,以前整合Spring MyBatis SpringMVC我们需要写一大堆的配置文件,堪称配置文件地狱,我们还要在pom.xml文件里引入各种类型的jar包,Mybatis的、SpringMVC的、Spring-aop的&a…

Tensorflow-reduce_sum 函数 Axis 详解

编程过程中经常需要对数组进行处理,而sum又是经常需要用到的函数,sum函数传参时会用到axis参数,低维度还好,高维度经常容易混淆,本文基于TF,对数组sum时axis进行详解,即对哪个位置加&#xff0c…

852. 山脉数组的峰顶索引

2021-06-15 LeetCode每日一题 链接&#xff1a;https://leetcode-cn.com/problems/peak-index-in-a-mountain-array/ 标签&#xff1a;二分 题目 符合下列属性的数组 arr 称为 山脉数组 &#xff1a; arr.length > 3存在 i&#xff08;0 < i < arr.length - 1&…

Scala Set使用与性能分析

Scala 经常遇到需要去重和取交集的情况&#xff0c;这里对Set简单使用和性能进行分析&#xff1a; val a Set(1,2,3)val b Set(2,3,4) 1.交集 println(a & b)println(a intersect(b)) 2.并集 println(a b)println(a | b)println(a.union(b)) 3.差集 差集需要注意前后…

Spark LogisticRegression 线性回归总结

LogisticRegression 是机器学习中最常用的算法&#xff0c;这里根据使用情况总结了Spark LR的使用demo: Tip: 本文使用数据格式为Libsvm 一.Lr线性回归推导与python实现在之前的博文已经介绍过 &#xff0c;本文着重介绍spark使用 https://blog.csdn.net/BIT_666/article/det…

io.netty | ERROR org.apache.spark.network.client.TransportClient - Failed to send RPC

问题&#xff1a; 使用Spark时 RDD的map&#xff0c;foreach等操作正常&#xff0c;执行collect到本地时报错&#xff0c;本地文件大小约为5m。 解决&#xff1a; 在博客上查报错信息有如下解释&#xff1a; 1.dirver端内存不足&#xff0c;spark强制关闭了任务&#xff0c…

483. 最小好进制

2021-06-18 LeetCode每日一题 链接&#xff1a;https://leetcode-cn.com/problems/smallest-good-base/ 标签&#xff1a;数学、二分查找 题目 对于给定的整数 n, 如果n的k&#xff08;k>2&#xff09;进制数的所有数位全为1&#xff0c;则称 k&#xff08;k>2&#xf…

java.lang.NoSuchMethodError 之 依赖冲突解决方案

NoSuchMethodError 解决方案大全 问题&#xff1a; 本机测试环境运行无误&#xff0c;在服务器和别的jar包一起打包在一起运行报错&#xff0c;这种大概率为依赖冲突问题 java.lang.NoSuchMethodError&#xff1a;com.google.protobuf.CodedInputStream.readStringRequireUtf…