linux|常用的脚本:

1.查找某个类在哪个jar包中:

#!/bin/bash
ls *.jar | while read jarfile;do echo "$jarfile";jar -tf $jarfile | grep " "; done

#优化后的
ls *.jar | while read jarfile;do jar -tf $jarfile | grep " "; if [$? -eq 0]; then echo "find class in jar:"$jarfile;fi; done

2.hdfs自动清理目录下过期的文件:

#!/bin/bash
# 将需要监控的目录放至数组中
yarn_log_dir=/app-logs/spark/logs
spark_log_dir=/spark-history
spark2_log_dir=/spark2-history
mr_log_dir=/mr-history/done/$(date +"%Y/%m" -d "-1 days")

array_check=($yarn_log_dir $mr_log_dir)

# 过期天数
expire_days=14

# 当前时间戳
today_timestamp=$(date -d "$(date +"%Y-%m-%d %H:%M")" +%s)

#Func: 删除指定时间之前的过期数据
removeOutDate(){
hadoop fs -ls $1 > temp_list.txt
cat temp_list.txt | while read quanxian temp user group size day hour filepath
do
current_file_time="$day $hour"
current_file_timestamp=$(date -d "$current_file_time" +%s)
if [ $(($today_timestamp-$current_file_timestamp)) -ge $(($expire_days*24*60*60)) ];then
echo "$day $hour $size $filepath"
hadoop fs -rm -r -skipTrash $filepath > /dev/null 2>&1
fi
done
}

#Func: 执行删除
execute(){
echo -e "\n\n"
echo "$(date +'%Y-%m-%d %H:%M:%S') start to remove outdate files in hdfs"
echo "$(date +'%Y-%m-%d %H:%M:%S') today is: $(date +"%Y-%m-%d %H:%M:%S")"

for i in ${array_check[@]}
do
echo "$(date +'%Y-%m-%d %H:%M:%S') processing filepath: $i"
removeOutDate $i
echo -e "\n"
done

echo "$(date +'%Y-%m-%d %H:%M:%S') remove outdate files in hdfs finished"
echo -e "\n\n"

rm -f temp_list.txt
}

# 开始执行
execute
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

数据湖填坑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值