Created
August 28, 2021 11:26
-
-
Save MocoNinja/87822dc4c9ec43ef81b8c59233657e1c to your computer and use it in GitHub Desktop.
Borrar Torrents Viejos
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 | |
ROOT_FOLDER="/mnt/Cosicas/Descargas/_TORRENTS/_TORRENT_FILES" | |
CLEAN_FOLDER="$ROOT_FOLDER/finished" | |
LOG="$ROOT_FOLDER/log.log" | |
### https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux | |
GREEN='\033[0;32m' | |
RED='\033[0;31m' | |
CYAN='\033[0;36m' | |
YELLOW='\033[0;33m' | |
NC='\033[0m' # No Color | |
echo -e "${CYAN}Iniciando pasada a $(date +%F---%T)${NC}" | tee -a $LOG | |
for torrent_file in $ROOT_FOLDER/*.torrent; do | |
file_name=$(basename $torrent_file) | |
## Saltar el por defecto | |
if [[ "$file_name" == "*.torrent" ]]; then | |
continue | |
fi | |
echo "Comprobando si \"$file_name\" está terminado..." | |
msg="\"$file_name\" no tiene match" | |
for torrent_file_finished in $CLEAN_FOLDER/*.torrent; do | |
file_name_finished=$(basename $torrent_file_finished) | |
if [[ "$file_name" == "$file_name_finished" ]]; then | |
msg="\"$file_name\" se ha detectado como finalizado" | |
continue | |
fi | |
done | |
if [[ "$msg" == "\"$file_name\" se ha detectado como finalizado" ]]; then | |
echo -e "${RED}** Hay que borrar \"$torrent_file\"${NC}" | tee -a $LOG | |
rm "$torrent_file" | |
erased="$erased\n$file_name" | |
else | |
echo -e "${GREEN}** \"$torrent_file\" aún se está descargando, por lo que hay que conservarlo...${NC}" | tee -a $LOG | |
fi | |
done | |
echo -e "${YELLOW}Ficheros borrados: $erased\n\n${NC}" | |
echo -e "${CYAN}Terminando pasada a $(date +%F---%T)${NC}" | tee -a $LOG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment