Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.19 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Source
  4. WATCH_DIR="/mnt/storage/Downloads"
  5.  
  6. # Targets
  7. DIR_VIDEOS="/mnt/storage/AutoSort/Videos/"
  8. DIR_FILME="/mnt/storage/AutoSort/Filme/"
  9. DIR_SERIEN="/mnt/storage/AutoSort/Serien/"
  10. DIR_PDF="/mnt/storage/AutoSort/PDFs/"
  11. DIR_ISO="/mnt/storage/AutoSort/ISOs/"
  12.  
  13.  
  14. inotifywait -m "$WATCH_DIR" -r -e close_write -e moved_to --format '%w%f' |
  15.     while read file; do
  16.  
  17.         # PDFs
  18.         if [[ "$file" =~ .*pdf$ ]]; then mv "$file" "$DIR_PDF"; fi
  19.  
  20.         # Filme und Serien --> klappt nur, wenn Serien schon die richtige Syntax haben (also nie ;-) )
  21.         if [[ "$file" =~ .*mkv$ ]];
  22.         then
  23.             if [[ $(echo "$file" | egrep -oE '[0-9]{1,2}x[0-9]{1,3}' | wc -c ) -ne 0 ]];
  24.  
  25.                     then    mv "$file" "$DIR_SERIEN";
  26.                     else    mv "$file" "$DIR_FILME";
  27.             fi;
  28.         fi
  29.  
  30.         # ISOs
  31.         if [[ "$file" =~ .*iso$ ]];
  32.             then mv "$file" "$DIR_ISO"
  33.         fi
  34.  
  35.  
  36.         # Videos
  37.         if [[ "$file" =~ .*mp4$ ]] || [[ "$file" =~ .*flv$ ]];
  38.             then mv "$file" "$DIR_VIDEOS"
  39.         fi
  40.  
  41.         # Entferne leere Ordner
  42.         find "$WATCH_DIR" -depth -type d -empty -exec rmdir -v {} \;;
  43.  
  44.     done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement