Cleanup Script – Delete hdfs tmp files

Delete /tmp files from hdfs which are older than 10 days
$ cat delete_hdfs_tmp_dir_files.sh

#!/usr/bin/env bash
### delete /tmp files from hdfs which are older than 10 days ###

IFS=$'\n'

today=`date +'%s'`

hadoop fs -ls -R /tmp | grep "^-" | while read line ; do
dir_date=$(echo ${line} | awk '{print $6}')
difference=$(( ( ${today} - $(date -d ${dir_date} +%s) ) / ( 24*60*60 ) ))
filePath=$(echo ${line} | awk '{print $8}')

if ([ "${difference}" -gt 10 ])
then
hadoop fs -rm -r ${filePath}
fi
done

hadoop fs -rm -r /user/hdfs/.Trash/Current/*
0 Comments

There are no comments yet

Leave a comment

Your email address will not be published. Required fields are marked *