Last active
September 24, 2024 19:18
-
-
Save kevinlu1248/2dea3c58363488580d7e63b4e4953ef2 to your computer and use it in GitHub Desktop.
Deletes untouched repos
This file contains 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 | |
# Function to safely remove a directory and echo the action | |
safe_remove() { | |
local dir="$1" | |
if [ -d "$dir" ]; then | |
echo "Removing: $dir" | |
rm -rf "$dir" | |
fi | |
} | |
# Main cleanup logic with echo for each removal | |
find ./caches/repos -type d -name base -print0 | \ | |
xargs -0 -I {} sh -c ' | |
dir_to_clean="$(dirname "{}")" | |
find "$dir_to_clean" -maxdepth 1 -type d ! -name base ! -name "$(basename "$dir_to_clean")" -print0 | \ | |
xargs -0 -I DIR safe_remove "DIR" | |
' sh safe_remove | |
echo "Cleanup completed." | |
# Crontab entry (run every day at 1:00 AM): | |
# 0 1 * * * /bin/bash /root/delete_old_repos.sh 2>&1 | logger -t delete_old_repos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment