#!/bin/bash# filename:deletehdfsdata.sh# traversal compresses all the files in the specified directory, parameters specify whether to delete the original file (2 parameters, 1 parameters is the directory, whether a parameter deletes the original file, 1 delete, 0 do not delete) # crontab: 30 2 * * * sh /application/aaa/enterprise/hadoop/ deletehdfsdata.sh >> /application/aaa/enterprise/hadoop/run.log 2>&1# Traverse to get all files in the specified directory, using GZ to compress # createdate: 20150909# author: yuanlong.zhoutoday= ' date day +%y-%m-%d ';echo "Today is ${today}" # get the date to delete # do not specify parameters, by default delete data starting with aaa-30 days ago (because it was deleted early in the morning, so it does not include the day) daynum= 5# parameter Error if [ $# -gt 1 ] ;then when the number of arguments is greater than 1 o'clock echo "Either do not pass parameters, or just pass 1 parameters!" exit 101;fi# gets the specified parameter when the number of arguments is 1 o'clock if [ $# == 1 ] ;then daynum=$1fihdfsday= ' date -d '-' "${daynum}" ' day ' +%y%m%d ';echo "${daynum} days ago is ${hdfsday}" Curl -xdelete http://localhost:9200/aaa-*-${hdfsday}hdfs dfs -rm -r /hnbc/${hdfsday}echo "${today } Execution Complete "
Crontab periodically deletes the specified HDFS data