-
-
Save carlosa8c/d228bac6dbf4ad244ac7f61edf2ec983 to your computer and use it in GitHub Desktop.
Script to list/delete old files in an HDFS Directory
This file contains hidden or 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 | |
usage="Usage: ./list-old-hdfs-files.sh [path] [days]" | |
if [ ! "$1" ] | |
then | |
echo $usage; | |
exit 1; | |
fi | |
if [ ! "$2" ] | |
then | |
echo $usage; | |
exit 1; | |
fi | |
now=$(date +%s); | |
# Loop through files | |
sudo -u hdfs hdfs dfs -ls $1 | while read f; do | |
# Get File Date and File Name | |
file_date=`echo $f | awk '{print $6}'`; | |
file_name=`echo $f | awk '{print $8}'`; | |
# Calculate Days Difference | |
difference=$(( ($now - $(date -d "$file_date" +%s)) / (24 * 60 * 60) )); | |
if [ $difference -gt $2 ]; then | |
# Insert delete logic here | |
echo "This file $file_name is dated $file_date."; | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment