Skip to content

Instantly share code, notes, and snippets.

@kanasite
Last active April 11, 2023 01:34
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanasite/2a90cbd419d5426a8ee313ffa43431c4 to your computer and use it in GitHub Desktop.
Save kanasite/2a90cbd419d5426a8ee313ffa43431c4 to your computer and use it in GitHub Desktop.
Remove Old plots by Interval
#!/bin/bash
## USAGE
## ./remove_plots.sh /PATH/TO/DIRECTORY/ 2021-07-01 30m
## first argument is path, must be end with trailing "/"
## second argument is target date, meaning plots that created after this date WILL NOT BE DELETED, if you specify 2021-07-01, only filename containing 2021-06-30 or before wil be deleted.
## third argument is the interval, adjust yourself according to your plotting speed or how soon you want to trigger next deletion.
SOURCE_DIR=$1
TARGET_DATE=${2:-"2021-07-01"}
INTERVAL=${3:-"30m"}
ARR=()
if [ -n "$1" ]; then
for entry in "$SOURCE_DIR"*
do
FILE_NAME=$(basename "$entry")
FILE_DATE=${FILE_NAME:9:10}
[[ $FILE_DATE < $TARGET_DATE ]] && ARR+=($entry)
done
echo "${#ARR[@]} plots to be removed:"
printf '%s\n' "${ARR[@]}"
for v in "${ARR[@]}"
do
echo "Sleeping for $INTERVAL..." && sleep $INTERVAL
echo "Removing $v" && rm $v
done
else
echo "first argument must be specified manually."
fi
@stefanmueller21
Copy link

thx for the script sorry for the nooby questions
In this chapter I need to create my values:
SOURCE_DIR=$1
TARGET_DATE=${2:-"2021-07-01"}
INTERVAL=${3:-"30m"}
? If yes the path just after $1 or can you make a sample?

Is it matter where I am storing the bash file or just copy it to the HDD?

@kanasite
Copy link
Author

thx for the script sorry for the nooby questions
In this chapter I need to create my values:
SOURCE_DIR=$1
TARGET_DATE=${2:-"2021-07-01"}
INTERVAL=${3:-"30m"}
? If yes the path just after $1 or can you make a sample?

Is it matter where I am storing the bash file or just copy it to the HDD?

u can run it like this:

/WHERE/YOU/PLACE/YOUR/SCRIPT/remove_plots.sh /WHERE/YOUR/PLOTS/FOLDERS/

@stefanmueller21
Copy link

:( not getting what do you mean

/WHERE/YOU/PLACE/YOUR/SCRIPT/remove_plots.sh /WHERE/YOUR/PLOTS/FOLDERS/
e.g.
C:/Desktop/remove_plots.sh /F:/?

@kanasite
Copy link
Author

it doesn't matter where u store the bash file as long as you have permission to run it, and the permission to remove the plots in your folder

@benjfranklin100
Copy link

Hi,

I was wondering if you could shed light on how a file is chosen once the source directory is scanned and found to have files with dates that are before the target date? E.g. the oldest file get selected, the newest file that still meets target criteria, etc. I tried to google how bash works in this instance but I'm new and wasn't able to find how dates in this instance would be handled.

Also, is there any way to have this cycle through multiple directories/drives? e.g. after processing disk 1 and waiting the specified interval it would go on to scan/process disk 2, then disk 3, etc...

@kanasite
Copy link
Author

Hi @benjfranklin100 , by default the sorting of the files in directory are alphabetically ordered, hence if u're using the default plot file name which will contain datetime, the oldest file in the directory will be get picked first.

This is just a simple bash (mainly used 1-off during the Chia plot format upgrade), u can clone it into multiple directories if u have multiple plotters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment