Advertisement
DaRealNG

Untitled

Dec 19th, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Directories to monitor (add your directories here)
  4. WATCH_DIRS=(
  5. "/path/to/dir1"
  6. "/path/to/dir2"
  7. )
  8.  
  9. # Subdirectory for extracted files (optional)
  10. EXTRACT_DIR="extracted"
  11.  
  12. # Function to extract RAR files
  13. extract_rar() {
  14. local rar_file="$1"
  15. local dest_dir="$(dirname "$rar_file")/$EXTRACT_DIR"
  16.  
  17. # Create the extraction directory if it doesn't exist
  18. mkdir -p "$dest_dir"
  19.  
  20. # Extract the RAR file
  21. unrar x -o+ "$rar_file" "$dest_dir"
  22. if [[ $? -eq 0 ]]; then
  23. echo "Extracted: $rar_file -> $dest_dir"
  24. else
  25. echo "Failed to extract: $rar_file"
  26. fi
  27. }
  28.  
  29. # Monitor directories for new .rar files
  30. echo "Monitoring directories for new .rar files..."
  31. inotifywait -m -e create --format '%w%f' "${WATCH_DIRS[@]}" | while read new_file; do
  32. # Check if the new file is a .rar
  33. if [[ "$new_file" =~ \.rar$ ]]; then
  34. echo "Detected new RAR file: $new_file"
  35. extract_rar "$new_file"
  36. fi
  37. done
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement