## 1. this is contents of your crontab file. run crontab -e to add these lines.## 2. you can use your username or your email as the last argument.## 3. make sure you are installing this on the machine where the directory is accessible,## i.e. if you check /scratch/local/... edit crontab on the machine with the directory of interest.## 4. use the absolute path to you directory, not the relative.## 5. this will check for old files (20 days and older) every day at noon (12:00); as a suggestion replace ## this with something else not to overload the server at the same time.## e.g. 27 15 * * * will run the script at 15:27.0 12 * * * /home/USERNAME/bin/notify_old.sh /scratch/beegfs/monthly/USERNAME/ 20 USERNAME
#!/bin/bash# this file needs to be executable, use chmod +x notify_old.sh# idea: Kamil Jaron, implementation: Iakov DavydovFILES_PATH="$1"DAYS=$2EMAIL="$3"if[[ ! $EMAIL]]thenecho"Usage: $(basename $0) DIR NDAYS EMAIL"exit1ficd"$FILES_PATH"||{echo"Couldn't change path, exiting "1>&2;exit1;}N_OLD_FILES=$(find -type f -mtime +$DAYS| wc -l)OLD_FILES=$(find -type f -mtime +$DAYS2> /dev/null | head -n 10)if[[$OLD_FILES]]then mail -s "Files will be deleted soon"$EMAIL<< ENDThere are $N_OLD_FILES files which will be deleted soon in $FILES_PATH.These files are older than $DAYS days.Here are some files:$OLD_FILESENDfi
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.